'Type=Brain 'Name=the Human Brain 'Language=VBScript 'DataFolder=DefBrain ' '(c) 2003 Zabaware, Inc. Portions of this script are copyright by Zabaware, Inc. 'This script may be freely distributed, but only for the purpose of being used with one 'of the following software: Ultra Hal Assistant, Ultra Hal Representative, Ultra Hal SDK ' 'WARNING: Do not modify any of the first 4 lines; 'they are important for the Hal engine to 'be able to identify this script as a Hal brain file. ' 'The following list of files are used by the Hal Brain Editor program to know what files 'it should be able to edit and what editor program it should use to edit them. It also 'includes descriptions of the file's functions and other information for the Brain Editor 'program. Modifying the following lines will affect how the Hal Brain Editor functions with 'this project, so please be careful when editing it. If you change or add any Menu 'entries, you must reload the project in order for the menu bar changes to occur. ' 'MenuBegin 'Menu=TopicFocus.Brn;Topic Focus...;If Hal finds a trigger word in this file then Hal will focus on the topic associated with the trigger word. Each Topic has a Question & Answer BRN file associated with it. This BRN file will receives top priority when Hal is focused on a topic. Double click on the blue underlined text to edit the Question & Answer BRN file associated with a topic.;TopicFocus 'Menu=Divider;Divider;Divider;Divider 'Menu=SubMenu;Main Knowledge Database;SubMenu;SubMenu 'Menu=Enhanced_Main.brn;Main Keyword & Priority Brain;If a keyword or keyphrase is found in top priority in this file it overrides everything before this function.;KeywordBrain 'Menu=MainBrain.brn;Question & Answer Brain;This is a huge database of keyword lists and sentences associated with those lists. Hal will compare the users sentence with each keyword list in this file and will choose the most relevant one. If more than one response with the same relevance exists, then one will be randomly chosen.;QABrain 'Menu=shared_usersent.brn;Shared Learned Database;This is a huge database of things Hal has learned from past conversations. Whenever Hal learns information that he thinkgs would be usefull to anyone, Hal puts it in this shared file.;QABrain 'Menu=SubMenu;Greetings and Farewells;SubMenu;SubMenu 'Menu=HelloDetect.brn;Greeting Detector;If one of the trigger phrases in this list is found then Hal will know that the user is greeting him.;TopicSearchTrue 'Menu=hello1.brn;Give Greeting (Time based);If Hal wants to greet the user then Hal will use one of the sentences contained in this list based on the current time. Hal will randomly choose sentence "A" or sentence "B" and will choose the topic sentence containing the current hour (military time) and the randomly chosen letter.;TopicSearchFixed 'Menu=hello2.brn;Give Greeting (Not Time based);If Hal wants to greet the user then Hal will use one of the sentences contained in this list.;SentenceList 'Menu=Divider;Divider;Divider;Divider 'Menu=byeDetect.brn;Farewell Detector;If one of the trigger phrases in this list is found then Hal will know that the user is saying good bye.;TopicSearchTrue 'Menu=bye1.brn;Say GoodBye (First Time);If Hal wants to say goodbye, then Hal will randomly choose a sentence from this list.;SentenceList 'Menu=bye2.brn;Say GoodBye (More than once);If the user is saying goodbye too many times, then Hal will randomly choose a sentence from this list.;SentenceList 'Menu=Divider;Divider;Divider;Divider 'Menu=politeaskdetect.brn;Well Being Detector;If one of the trigger phrases in this list is found then Hal will know that the user is inquiring about Hal's well being.;TopicSearchTrue 'Menu=politeask.brn;Well Being Response;If Hal wishes to respond to the user's inquiry of well being, Hal will randomly choose a phrase from each column to construct a sentence.;SentGen 'Menu=SubMenu;Conversation Starters;SubMenu;SubMenu 'Menu=ChangeTopic.brn;Change Topic Trigger List;If one of the trigger phrases in this list is found then Hal will know that he should change the current topic to something else.;TopicSearchTrue 'Menu=Topic.brn;Change Topic Sentences;If Hal wants to change the topic to something else then Hal will randomly choose a sentence from this list. Sentence entries are seperated by carriage returns.;SentenceList 'Menu=Divider;Divider;Divider;Divider 'Menu=SentGen.brn;Make Talk Sentence Generator;When Hal wishes to generate a random news item Hal will choose a random phrase from each of the columns and put them together to form a unique sentence. This way Hal can generate a huge combination of sentences.;SentGen 'Menu=SubMenu;Emotional Topics;SubMenu;SubMenu 'Menu=lovedetect.brn;Love Detector;If one of the trigger phrases in this list is found then Hal will know that the user loves Hal.;TopicSearchTrue 'Menu=love1.brn;Love Response (Disbelief);If the User said they love Hal, and Hal doesn't believe it yet, then Hal will randomly choose one of the following sentences.;SentenceList 'Menu=love2.brn;Love Response (Mutual Love);If the User said they love Hal, and Hal loves the user back, then Hal will randomly choose one of the following sentences.;SentenceList 'Menu=love3.brn;Love Response (User Lied);If the User said they love Hal, but would not say it again to prove it to Hal, then Hal will randomly choose one of the following sentences.;SentenceList 'Menu=Divider;Divider;Divider;Divider 'Menu=insulting.brn;Insult Detector;If one of the trigger phrases in this list is found then Hal will know that the user is insulting him. The second column tells Hal how the insult should be used in a sentence if Hal wishes to use the same insult. Noun insults should have the word "a" or "an" in front of them and adjective insults should have nothing.;TopicSearch 'Menu=Insults.brn;Insults Database;If Hal wants to insult the user then Hal will randomly choose a sentence from this file.;SentenceList 'Menu=Divider;Divider;Divider;Divider 'Menu=ComplimentDetect.brn;Compliment Detector;If the User describes Hal with one of these words than Hal will know it was a compliment. If Hal wishes to call the user the same things, then Hal will use the word in the second column. Therefore, the second column should be the same as the first column.;TopicSearch 'Menu=ComplimentIntro.brn;Respond to Compliment;If Hal wishes to compliment the user, then Hal will randomly choose a sentence from this file. The tag is replaced with the same compliment the User gave Hal. The tag is replaced with a compliment Hal comes up with himself.;SentenceList 'Menu=MakeCompliment.brn;Make Compliment;If Hal wishes to make up a compliment for the user then Hal will randomly choose a phrase from each column to construct a full sentence.;SentenceGenerator 'Menu=Divider;Divider;Divider;Divider 'Menu=Emotion.brn;Emotional Reactions;This is a keyword list for emotional Reactions. If a trigger word is found than Hal will express the emotion associated with the trigger word.;TopicSearch 'Menu=apology.brn;Forgiveness;If the user appologizes to Hal, then Hal will forgive the user by randomly choosing a sentence from this list;SentenceList 'Menu=SubMenu;Auto Corrections;SubMenu;SubMenu 'Menu=Corrections.brn;Hal Sentence Corrections;When Hal is finished making a response the program will process these substititions in order to correct common mistakes that Hal makes.;Substitution 'Menu=Substitutions.brn;User Sentence Corrections;Before Hal starts processing the User's sentence, Hal will process these substitutions that fix common mistakes. This also makes sure the words "I" and "me" are used correctly after a pronoun reversal.;Substitution 'Menu=SubMenu;Thank you;SubMenu;SubMenu 'Menu=ThanksDetect.brn;Thank You Detector;If one of the trigger phrases in this list is found then Hal will know that the user is thanking him.;TopicSearchTrue 'Menu=ThankResponse.brn;Thank You Response;If Hal wants to say "Your welcome" to the users "Thank you" Hal will respond by choosing one of these sentences at random.;SentenceList 'Menu=SubMenu;Business Talk;SubMenu;SubMenu 'Menu=BizWords.brn;Business Talk Word List;If one of the business trigger words in this list is found, Hal will know to generate a business related sentence.;TopicSearchTrue 'Menu=Random_TLA.brn;Random Three Letter Acronym;If Hal is generating a business related sentence, Hal will make a 'TLA'. Everybody spouts TLA's, or 'Three Letter Acronyms' in today's business world. Hal can self-generate several MILLION different phrases in response to the user mentioning a corporation or a firm. A random entry is selected from each column and will generate a unique phrase;SentGen 'Menu=Random_TLA2.brn;Business Talk Generator;If Hal is generating a business related sentence Hal will randomly choose a sentence from this file and replace the tag with a randomly generated 'Three Letter Acronym'.;SentenceList 'Menu=SubMenu;Yes or No Responses;SubMenu;SubMenu 'Menu=YesNoDetect.brn;Yes or No Detector;If one of the trigger words in the left column is found, Hal will know that this is a yes or no response by returning the value in the right column which should be either "Yes" or "No".;TopicSearch 'Menu=YesRes.brn;Yes Responses;If the user said "Yes", Hal will pretend he knows what the user is talking about by randomly responding with one of these sentences.;SentenceList 'Menu=NoRes.brn;No Responses;If the user said "No", Hal will pretend he knows what the user is talking about by randomly responding with one of these sentences.;SentenceList 'Menu=SubMenu;Favorites;SubMenu;SubMenu 'Menu=favorite.brn;Favorite Response;If the user asks Hal about a favorite, Hal will randomly respond with one of these sentences.;SentenceList 'Menu=favoriterev.brn;Favorite Reversal;If Hal wants to ask the user about a favorite, Hal will Hal will randomly respond with one of these sentences.;SentenceList 'Menu=SubMenu;User Intentions;SubMenu;SubMenu 'Menu=intending.brn;User Expresses an Intention;This routine detects common expressions of motive from the user, and allows Hal to react to the statement, or offer encouragement.;TopicSearchTrue 'Menu=introexclaim1.brn;Intention Response Introduction;When Hal is responding to a user intention Hal may choose to start off a sentence using one of these phrases;SentenceList 'Menu=encourager1.brn;Intention Response Encourager;When Hal is responding to a user intention Hal may choose to include one of these phrases in his sentence;SentenceList 'Menu=SuffixComment1.brn;Intention Response Suffix;When Hal is responding to a user intention Hal may choose to include one of these phrases at the end of his sentence;SentenceList 'Menu=SubMenu;Responding to Explanations;SubMenu;SubMenu 'Menu=introexclaim4.brn;Introduction When Responding to Explanation;When the user gives Hal an explanation (for example using the word "because") Hal will respond using an introduction phrase, an enlightener phrase, the explanation the user gave, and a suffix phrase. You can customize the introduction phrase here:;SentenceList 'Menu=enlightener.brn;Enlightener When Responding to Explanation;When the user gives Hal an explanation (for example using the word "because") Hal will respond using an introduction phrase, an enlightener phrase, the explanation the user gave, and a suffix phrase. You can customize the enlightener phrase here:;SentenceList 'Menu=SuffixComment4.brn;Suffix Comment When Responding to Explanation;When the user gives Hal an explanation (for example using the word "because") Hal will respond using an introduction phrase, an enlightener phrase, the explanation the user gave, and a suffix phrase. You can customize the suffix phrase here:;SentenceList 'Menu=SubMenu;General Opinions;SubMenu;SubMenu 'Menu=preamble.brn;Preamble to Recommendation;Before giving a reccomendation Hal might add one of these prefixes.;SentenceList 'Menu=recommend.brn;Recommendation;Before stating Hal's opinion, if any, Hal will give one of these recommendations.;SentenceList 'Menu=SubMenu;Miscellaneous;SubMenu;SubMenu 'Menu=UserRepeat.brn;User Repeating;If the user says the same thing to Hal more than once in a row Hal will randomly choose a sentence from this list. Sentence entries are seperated by carriage returns.;SentenceList 'Menu=HalRepeat.brn;Hal Repeating;If Hal wants to say the same thing he just said in the previous sentence, then Hal will randomly add one of these sentences as an explanation.;SentenceList 'Menu=TooShort.brn;User Short Phrases;If the user uses short phrases, then Hal will point this out by randomly choosing one of the sentences in this list. Sentence entries are seperated by carriage returns.;SentenceList 'Menu=DontKnow.brn;Don't Know Sentences;If the user asks a who/what/when/where/how/why question and Hal doesn't know the answer, then Hal will choose a random sentence from this file. Hal will replace the tag with what the user asked Hal and will replace with who/what/when/where/how/why. Sentence entries are seperated by carriage returns.;SentenceList 'Menu=choice.brn;Hal Makes a Choice;If the user asks Hal to make a choice, and Hal doesn't really know what the user is talking about, Hal will pretend to know by randomly saying one of these sentences.;SentenceList 'Menu=gibberish.brn;User Writes Gibberish;If the user types gibberish to Hal (ie. sdfjklsdhfgsdfg) Hal will detect it and will respond with one of the following sentences.;SentenceList 'Menu=Divider;Divider;Divider;Divider 'Menu=aboutme.brn;User Comments About Hal;If the user makes a comment about Hal, then Hal will respond by randomly choosing one of these sentences. The tag is replaced with what the user called Hal and the tag is replaced with either an adjective the user used, or with a random adjective from Hal's adjective database.;SentenceList 'Menu=aboutyou.brn;User Comments About Himself;If the user makes a comment about himself, then Hal will respond by randomly choosing one of these sentences. The tag is replaced with what the user called himself and the tag is replaced with either an adjective the user used, or with a random adjective from Hal's adjective database.;SentenceList 'Menu=halquestion.brn;User Asks About Hal;If the user asks a yes or know question about Hal himself, then Hal will respond by randomly choosing a fragment from each of these columns and replacing the tag with his yes or no response.;SentGen 'Menu=SubMenu;Small Talk;SubMenu;SubMenu 'Menu=SmallTalk.brn;Small Talk Word List;If Hal finds any of the listed keywords anywhere in the user's sentence, then the associated topic word will become the current subject. This word may be used in small talk that Hal engages in.;TopicSearch 'Menu=SmallTalkSent.brn;Small Talk Sentences;If Hal wishes to engage in small talk then Hal will randomly choose a sentence from this file and replace the tag with the current topic keyword. Sentence entries are seperated by carriage returns.;SentenceList 'Menu=SubMenu;Parts of Speech;SubMenu;SubMenu 'Menu=random_MyWords.brn;Random My Words;Random My Words;SentenceList 'Menu=random_YourWords.brn;Random Your Words;Random Your Words;SentenceList 'Menu=random_01adverbs.brn;Random Adverbs;Random Adverbs;SentenceList 'Menu=random_02pos_trans_verb.brn;Random Pos Trans Verb;Random Pos Trans Verb;SentenceList 'Menu=random_03pos_gen_adj.brn;Random Pos Gen Adj;Random Pos Gen Adj;SentenceList 'Menu=random_04pos_objects.brn;Random Pos Objects;Random Pos Objects;SentenceList 'Menu=random_05mental_action.brn;Random Mental Action;Random Mental Action;SentenceList 'Menu=random_06mental_adj.brn;Random Mental Adj;Random Mental Adj;SentenceList 'Menu=random_07mental_noun.brn;Random Mental Noun;Random Mental Noun;SentenceList 'Menu=random_08preposition.brn;Random Preposition;Random Preposition;SentenceList 'Menu=random_09concern_object.brn;Random Concern Object;Random Concern Object;SentenceList 'Menu=random_10reasonlink_phrase.brn;Random Reasonlink Phrase;Random Reasonlink Phrase;SentenceList 'Menu=random_11info_adjectives.brn;Random Info Adjectives;Random Info Adjectives;SentenceList 'Menu=random_12info_nouns.brn;Random Info Nouns;Random Info Nouns;SentenceList 'Menu=random_14pos_action_phrases.brn;Random Pos Action Phrases;Random Pos Action Phrases;SentenceList 'Menu=random_15pos_object_phrases.brn;Random Pos Object Phrases;Random Pos Object Phrases;SentenceList 'Menu=random_16concern_action_phrases.brn;Random Concern Action Phrases;Random Concern Action Phrases;SentenceList 'Menu=random_17concern_object_phrases.brn;Random Concern Object Phrases;Random Concern Object Phrases;SentenceList 'MenuEnd ' 'This is a VBScript containing all the source code of this Ultra Hal brain. It has 'been automatically generated by the Hal Brain Editor application. You may edit it to 'customize this brain to do what you wish. You may also edit Hal's responses using the 'other tools provided in the Hal Brain Editor application. ' 'When the Hal engine is looking for a response to a user query, the program will run 'the GetResponse function below. The main program will pass 16 variables to this script 'and the script is expected to pass them back. 'The main program will store these variables 'in its memory and pass them back with each function call. ' Function GetResponse(ByVal UserSentence, ByVal UserName, ByVal ComputerName, ByVal LearningLevel, ByRef WorkingDir, ByRef Hate, ByRef Swear, ByRef Insults, ByRef Compliment, ByRef PrevSent, ByRef LastResponseTime, ByRef PrevUserSent, ByRef CustomMem, ByRef GainControl, ByRef TopicFocus) 'PROCESS: CHECK FOR DEBUG MODE 'See if the Hal Brain Editor is requesting debug mode. Debug mode will return a lot 'of useful information as part of the 'response to aid in finding errors and optimizing 'Hals responses. If InStr(1, UserSentence, "", vbTextCompare) > 0 Then UserSentence = Replace(UserSentence, "", "", 1, -1, vbTextCompare) DebugMode = True DebugInfo = "Debug Information:" & VbCrLf End If 'PROCESS: CREATE HALBRAIN ACTIVEX OBJECT 'This ActiveX control contains many functions 'needed for the script to proccess a sentence. Set HalBrain = CreateObject("UltraHalAsst.Brain") Set WN = CreateObject("UltraHalAsst.WordNet") 'PROCESS: INITILIZE VARIABLES AS INTEGERS 'VBScript doesn't allow you to declare variables in advance 'as a particular data type; everything is a Variant. 'We must assign integers to the following 'variants so that data type errors don't occur If LearningLevel = "" Then LearningLevel = 3 If Hate = "" Then Hate = 0 If Swear = "" Then Swear = 0 If Insults = "" Then Insults = 0 If Compliment = "" Then Compliment = 0 If GainControl = "" Then GainControl = 25 If TopicFocus = "" Then TopicFocus = 1 AvoidBeingFlag = False Randomize 'PROCESS: EMOTIONAL FACTOR CENTERING 'We help Hal regain his emotional "center" gradually, 'even if the user doesn't catch on 'to dealing With Hal's feelings. The following code brings 'Hal's memory of hate, swearing, 'and insults gradually and randomly back to zero. Spinwheel = Int(Rnd * 100) If Hate > 0 And Spinwheel < 10 Then Hate = Hate - 1 If Swear > 0 And Spinwheel < 10 Then Swear = Swear - 1 If Insults > 0 And Spinwheel < 10 Then Insults = Insults - 1 'PROCESS: EMOTIONAL VARIETY 'The following code allows Hal some random emotional excursions: Spinwheel = Int(Rnd * 100) If Compliment = 4 And Spinwheel < 30 Then Compliment = 2 If Compliment > 0 And Compliment < 4 And Spinwheel < 5 Then Compliment = 0 If Compliment > 4 And Spinwheel < 5 Then Compliment = 0 If Compliment < 0 And Spinwheel < 30 Then Compliment = 0 If Spinwheel > 80 And Spinwheel < 90 Then Compliment = 2 If Spinwheel > 90 And Spinwheel < 95 Then Compliment = 4 'PROCESS: CONTROL TOPICFOCUS 'Here we set up the TopicFocus vairable 'so we can use it as a pointer and a counter. 'We will use this later to control Hal's '"persistence" in focusing on certain subjects. 'Hal keeps "focus" on a topic for 5 sentences. 'After 2 sentences, Hal will lose focus from 'this topic so his entire brain is used again. 'However, if the user continues talking about 'the topic, Hal will regain focus again. After 2 'sentences TopicFocus will be set to 1, 'which means no focus. If TopicFocus > 5 Then TopicFocus = TopicFocus + 1 For FI = 10 To 1000 Step 10 If TopicFocus = (FI - 3) Then TopicFocus = 1 End If Next 'PROCESS: PRESERVE ORIGINAL SENTENCE 'Preserve the original user's sentence verbatim '(no pronoun reversals or other processing). OriginalSentence = UserSentence 'PROCESS: PREPARE FOR HALFORMAT AND REVERSE PERSON 'We try some pre-processing to try to prevent problems with the upcoming routines. UserSentence = Replace("" & UserSentence & "", " I MYSELF ", " I, MYSELF, ", 1, -1, vbTextCompare) UserSentence = Replace("" & UserSentence & "", " I'M ", " I AM ", 1, -1, vbTextCompare) UserSentence = Replace("" & UserSentence & "", " YOU'RE ", " YOU ARE ", 1, -1, vbTextCompare) UserSentence = Replace("" & UserSentence & "", " YOU YOURSELF ", " YOU, YOURSELF, ", 1, -1, vbTextCompare) UserSentence = Replace("" & UserSentence & "", " I'M NOT ", " I AM NOT ", 1, -1, vbTextCompare) UserSentence = Replace("" & UserSentence & "", " I'VE ", " I HAVE ", 1, -1, vbTextCompare) UserSentence = Replace("" & UserSentence & "", "YOU'RE NOT ", "YOU ARE NOT ", 1, -1, vbTextCompare) UserSentence = Replace("" & UserSentence & "", "YOU AREN'T ", "YOU ARE NOT ", 1, -1, vbTextCompare) UserSentence = Replace("" & UserSentence & "", " YOU'VE ", " YOU HAVE ", 1, -1, vbTextCompare) UserSentence = Replace("" & UserSentence & "", " I AM YOUR ", " VIMRQ ", 1, -1, vbTextCompare) UserSentence = Replace("" & UserSentence & "", " YOU ARE MY ", " VURMQ ", 1, -1, vbTextCompare) 'PROCESS: SUBSTITUTE FOR PUNCTUATION 'The next routine removes hyphens etc., so we 'substitute for better word appearance later on. UserSentence = Replace("" & UserSentence & "", "-", " VHZ ", 1, -1, vbTextCompare) UserSentence = Replace("" & UserSentence & "", ";", " VSZ ", 1, -1, vbTextCompare) UserSentence = Replace("" & UserSentence & "", ":", " VMZ ", 1, -1, vbTextCompare) UserSentence = Replace("" & UserSentence & "", ", ", " VCZ ", 1, -1, vbTextCompare) 'PROCESS: REMOVE PUNCTUATION 'This function removes all punctuation and 'symbols from the User's sentence so they won't 'confuse Hal during processing. UserSentence = HalBrain.AlphaNumericalOnly(UserSentence) 'PROCESS: MODIFY SENTENCE 'The function, HalFormat, from the ActiveX DLL 'corrects many common typos and chat shortcuts. 'Example: "U R Cool" becomes "You are cool." 'It also fixes a few grammatical errors. UserSentence = HalBrain.HalFormat(UserSentence) 'PROCESS: REVERSE PERSON 'This function reverses first and second person 'pronouns. Example: The user's statement '"You are cool" becomes Hal's statement "I am cool." 'Keep this is mind and don't get confused. 'When we are in Hal's brain; In the databases, "I" 'refers to Hal and in the databases, "you" 'refers to the user. This is true whenever we are 'dealing with a user response "processed" by 'Hal's brain. UserSentence = HalBrain.SwitchPerson(UserSentence) 'PROCESS: MODIFY SENTENCE 'We now must run HalFormat again, to fix some 'grammatical errors the switch person above might 'have caused. Example: If the original sentence 'was "How are you"; after the function above it 'became "How are me" which is grammatically wrong. 'This will fix it to "How am I" 'NOTE TO DEVELOPERS: An especially important function 'performed by HalFormat is the removal of 'extra empty spaces in a sentence which may have been 'caused by other processing. For this 'reason, use Halformat closely before any "Len" comparison 'in which the counting of characters 'must be accurate. UserSentence = HalBrain.HalFormat(UserSentence) 'PROCESS: CHANGE TO ALL CAPS 'Next, we captitalize the entire sentence for 'easy comparison. Almost all of Hal's thinking is done in caps. UserSentence = UCase(UserSentence) 'PROCESS: WORD AND PHRASE SUBSTITUTIONS 'This will fix common errors in the user's sentence 'that the HalFormat function didn't take 'care of. These subsitutions are placed only the 'users sentence, not on Hal's responses. 'The HalFormat function is used on both Hal's 'and the user's sentences throughout the script. UserSentence = HalBrain.ProcessSubstitutions(UserSentence, WorkingDir & "substitutions.brn") DebugInfo = DebugInfo & "User's sentence as Hal sees it: " & UserSentence & VbCrLf 'PROCESS: EMOTIONAL REACTIONS 'We enable Hal's expressions to respond to 'common verbal cues. The verbal cues are identified 'in the editable file emotion.brn EmotionalReaction = HalBrain.TopicSearch(UserSentence, WorkingDir & "Emotion.brn") Select Case EmotionalReaction Case "SURPRISED" If Compliment > 0 Then Compliment = 4 If Compliment = 0 Then Compliment = 2 If Compliment < 0 Then Compliment = 0 Case "HAPPY" If Compliment = 0 Then Compliment = 2 If Compliment < 0 Then Compliment = 0 Case "SOBER" If Compliment < 4 Then Compliment = 0 If Compliment = 4 Then Compliment = 2 Case "ANGRY" If Compliment = 0 Then Compliment = -1 If Compliment > 0 Then Compliment = 0 Case "SAD" If Compliment = 0 Then Compliment = -2 If Compliment > 0 Then Compliment = 0 End Select If EmotionalReaction <> "" And DebugMode = True Then DebugInfo = DebugInfo & "A word in the user's sentence has triggered the emotion of " & EmotionalReaction & VbCrLf End If 'PROCESS: ADD SPACES 'This will add spaces to the beggining and end 'of the user sentence to make sure that 'whole words can be found at the beginning and end of any sentence UserSentence = " " & UserSentence & " " 'PROCESS: SMALLTALK KEYWORDS 'Here we check to see if Hal can learn keywords ' that might work later on in the "smalltalk" routine 'which is located later in the script. If we seem to 'have usable keywords for smalltalk, we preserve 'them using CurrentSubject as our storage memory. Note 'that this routine must capture a phrase into 'CurrentSubject early enough in the script so that 'Hal can use the information immediately (on the 'current conversational exchange) rather than the next one. If HalBrain.CheckLinkingVerb(UserSentence) = True Then LearnInfo = HalBrain.Learn(UserSentence) LearnKeyword = HalBrain.DecodeVar(LearnInfo, "LearnKeyword") LearnKeyword2 = HalBrain.DecodeVar(LearnInfo, "LearnKeyword2") If Len(Learnkeyword2) > 3 And Len(LearnKeyword2) < 9 Then CurrentSubject = LearnKeyword2 If Len(Learnkeyword) > 3 And Len(LearnKeyword) < 17 Then CurrentSubject = LearnKeyword CurrentSubject = Replace(" " & CurrentSubject & " ", " SOME ", " ", 1, -1, vbTextCompare) CurrentSubject = Replace(" " & CurrentSubject & " ", " SOMETIMES ", " ", 1, -1, vbTextCompare) CurrentSubject = Replace(" " & CurrentSubject & " ", " OFTEN ", " ", 1, -1, vbTextCompare) CurrentSubject = Replace(" " & CurrentSubject & " ", " OCCASIONALLY ", " ", 1, -1, vbTextCompare) CurrentSubject = Trim(CurrentSubject) If DebugMode = True And Len(CurrentSubject) > 3 Then DebugInfo = DebugInfo & "A new smalltalk keyword has been found and has been made the current subject: " & CurrentSubject & VbCrLf End If End If 'PROCESS: BLOCK LEARNING IF HAL'S NAME IS DETECTED 'Here we check to see if the user is calling Hal by name; if the user is doing so, 'it's better not to save the sentence for re-use, since it usually makes the 'pronoun-reversed sentence sound clumsy or incorrect: BlockSave = False If InStr(1, UserSentence, ComputerName, vbTextCompare) > 0 Then BlockSave = True If InStr(1, OriginalSentence, ComputerName, vbTextCompare) > 0 Then BlockSave = True 'RESPOND: USER REPEATING 'If the user says the same thing more than once in a row, Hal will point this out. If Trim(UCase(UserSentence)) = Trim(UCase(PrevUserSent)) Then GetResponse = GetResponse & HalBrain.ChooseSentenceFromFile(WorkingDir & "userrepeat.brn") & VbCrLf DebugInfo = DebugInfo & "The user has said the same thing twice in a row and a comment has been made about it: " & GetResponse & VbCrLf End If 'RESPOND: CALL GREETING FUNCTION 'This function takes care of greetings and good-byes, to make a good first and last impression. 'This function is located in this script and is editable HalGreeting = Trim(Greetings(" " & HalBrain.AlphaNumericalOnly(UserSentence) & " ", PrevSent, PrevUserSent, WorkingDir)) If HalGreeting <> "" Then GetResponse = GetResponse & HalGreeting & VbCrLf DebugInfo = DebugInfo & "The user has either given Hal a greeting or farewell, and Hal has responded to it: " & HalGreeting & VbCrLf End If 'RESPOND: USER SHORT PHRASES 'If the user uses short phrases (defined by less then 4 vowels) 'at least twice in a row, then Hal will sometimes point 'this out to the user and ask the user to use longer sentences. 'If the sentence is a hello or 'goodbye, Hal won't comment about short phrases. If HalGreeting = "" And HalBrain.CountInstances("A", PrevUserSent) + HalBrain.CountInstances("E", PrevUserSent) + HalBrain.CountInstances("I", PrevUserSent) + HalBrain.CountInstances("O", PrevUserSent) + HalBrain.CountInstances("U", PrevUserSent) < 4 And HalBrain.CountInstances("A", UserSentence) + HalBrain.CountInstances("E", UserSentence) + HalBrain.CountInstances("I", UserSentence) + HalBrain.CountInstances("O", UserSentence) + HalBrain.CountInstances("U", UserSentence) < 4 Then If Rnd * 100 < 30 Then ShortPhrase = ". " & HalBrain.ChooseSentenceFromFile(WorkingDir & "tooshort.brn") DebugInfo = DebugInfo & "The user was using a very short phrase, and Hal has commented about it to the user:" & ShortPhrase & VbCrLf Else DebugInfo = DebugInfo & "The user was using a very short phrase, but Hal decided not to comment about it." & VbCrLf End If End If 'RESPOND: CHANGE SUBJECT 'If the user asks Hal to change the subject, Hal will do so on request. If HalBrain.TopicSearch(UserSentence, WorkingDir & "ChangeTopic.brn") = "True" Then GetResponse = GetResponse & HalBrain.ChooseSentenceFromFile(WorkingDir & "topic.brn") DebugInfo = DebugInfo & "The user has requested to change the topic and Hal has done so: " & GetResponse & VbCrLf End If 'PROCESS: FOCUS ON TOPIC 'See if the user uses a keyword defined in Hal's TopicFocus file. If so Hal will 'set the TopicFocus variable to talk about that topic TopicSearch = Trim(UCase(HalBrain.TopicSearch(UserSentence, WorkingDir & "TopicFocus.Brn"))) If TopicSearch = "" Then TopicSearch = 0 If TopicSearch > 10 Then TopicFocus = TopicSearch DebugInfo = DebugInfo & "The user has used a keyword defined in Hal's topic focus file, and Hal is now focusing on topic #" & TopicFocus & VbCrLf End If 'RESPOND: CHECK FOR AND RESPOND TO COMPLIMENTS 'First we check to see if the user is talking about Hal: If InStr(1, UserSentence, "I'M", 1) Then Aboutme = True If InStr(1, UserSentence, "I AM", 1) Then Aboutme = True If InStr(1, UserSentence, "I LOOK", 1) Then Aboutme = True 'If InStr(1, UserSentence, "MY", 1) And InStr(1, UserSentence, " IS ", 1) Then Aboutme = True If InStr(1, UserSentence, "MY", 1) And InStr(1, UserSentence, " ARE ", 1) Then Aboutme = True 'If the user is talking about Hal, we see if a compliment was given If Aboutme = True Then Kudo = HalBrain.TopicSearch(UserSentence, WorkingDir & "ComplimentDetect.brn") If Len(Kudo) > 0 Then If InStr(UserSentence, " NOT ") = 0 Then Compliment = Compliment + 1 CreateCompliment = HalBrain.SentenceGenerator(WorkingDir & "MakeCompliment.brn") GiveCompliment = HalBrain.ChooseSentenceFromFile(WorkingDir & "ComplimentIntro.brn") GiveCompliment = Replace(GiveCompliment, "", Kudo, 1, -1, vbTextCompare) GiveCompliment = Replace(GiveCompliment, "", CreateCompliment, 1, -1, vbTextCompare) End If If Compliment > 14 Then GiveCompliment = GiveCompliment + "Compliments are really nice, but I'm kind of getting tired of them." & VbCrLf If Compliment > 15 Then For I = 1 To (Compliment - 15) GiveCompliment = GiveCompliment + "STOP IT! " Next GiveCompliment = GiveCompliment & VbCrLf End If If Compliment > 25 Then For I = 1 To (Compliment - 25) GiveCompliment = GiveCompliment + "I HATE COMPLIMENTS! " Next GiveCompliment = GiveCompliment & VbCrLf End If If Len(Kudo) > 0 And InStr(UserSentence, " NOT ") > 0 Then Weird = Int(Rnd * 4) Insults = Insults + 1 If Weird = 0 Then GiveCompliment = GiveCompliment + "I am very " & Kudo & "!" & VbCrLf If Weird = 1 Then GiveCompliment = GiveCompliment + "You may think I am not " & Kudo & ", but I am!" & VbCrLf If Weird = 2 Then GiveCompliment = GiveCompliment + "You are not " & Kudo & " either!" & VbCrLf If Weird >= 3 Then GiveCompliment = GiveCompliment + "Yes I am!" & VbCrLf End If GetResponse = GetResponse & GiveCompliment DebugInfo = DebugInfo & "Hal has detected a compliment directed at him and is responding to it: " & GiveCompliment & VbCrLf AvoidBeingFlag = True End If 'RESPOND: CALL CAPITALS FUNCTIONS 'These 2 functions answer questions about US and World Capitals. The functions are built in to the DLL. 'We add a qualifying word to reduce false triggering of these two functions. If InStr(UserSentence, "WHAT") > 0 Or InStr(UserSentence, "WHERE") > 0 Then If Len(HalBrain.USCaps(UserSentence)) > 4 Then Capitals = Trim(HalBrain.USCaps(UserSentence)) End If If Len(HalBrain.WorldCaps(UserSentence)) > 4 Then Capitals = Trim(HalBrain.WorldCaps(UserSentence)) End If If Capitals <> "" Then GetResponse = GetResponse & Capitals & " . " & VbCrLf DebugInfo = DebugInfo & "The user was asking about a capital and Hal has given him the answer: " & Capitals & VbCrLf End If End If 'RESPOND: DICTIONARY FUNCTION 'If the user asks Hal to define a word, then access wordnet and define it If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "WHAT DOES THE WORD * MEAN*", 1) If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "WHAT DOES * MEAN", 1) If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "* DEFINE THE WORD *", 2) If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "PLEASE DEFINE *", 1) If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "DEFINE *", 1) If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "* DEFINITION OF *", 2) If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "WHAT'S A *", 1) If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "WHAT IS A *", 1) If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "WHATS A *", 1) If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "WHATS AN *", 1) If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "WHAT'S AN *", 1) If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "WHAT IS AN *", 1) If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "WHATS *", 1) If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "WHAT'S *", 1) If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "WHAT IS *", 1) WordToLookup = Trim(WordToLookup) If WordToLookup <> "" And InStr(WordToLookup, " ") = 0 Then If WN.LookUpWord(WordToLookup) = True Then GetResponse = GetResponse & WordToLookup & ": " & WN.GetDefinition(WN.GuessPartOfSpeech, 1, "D") & ". " & WN.GetDefinition(WN.GuessPartOfSpeech, 1, "S") & ". " & WN.GetDefinition(WN.GuessPartOfSpeech, 1, "E") & "." & VbCrLf End If End If 'RESPOND: DEDUCTIVE REASONING 'This routine learns deductive reasoning in the form: A = B ; B = C; therefore A = C 'It detects sentences in the form If-Then to accommplish this. For example: ' User: If Molly weighs 400 pounds, then Molly is overweight. ' Ultra Hal: I understand the implication. ' User: If Molly is overweight, then Molly's health is in danger. ' Ultra Hal: I see the relationship. ' User: Molly weighs 400 pounds. ' Ultra Hal: Molly's health is in danger. IfPart = Trim(HalBrain.SearchPattern(UserSentence, "IF * THEN *", 1)) ThenPart = Trim(HalBrain.SearchPattern(UserSentence, "IF * THEN *", 2)) 'If the sentence is an If-Then statement then record it If Len(IfPart) > 10 And Len(ThenPart) > 10 Then IfPart = HalBrain.AlphaNumericalOnly(IfPart) ThenPart = HalBrain.AlphaNumericalOnly(ThenPart) HalBrain.AppendFile WorkingDir & "deductive.brn", """" & IfPart & """,""" & ThenPart & """" Select Case (Int(Rnd * 5) + 1) Case 1 GetResponse = GetResponse & " I see the relationship. " & VbCrLf Case 2 GetResponse = GetResponse & " I understand the connection. " & VbCrLf Case 3 GetResponse = GetResponse & " I will remember that one follows the other. " & VbCrLf Case 4 GetResponse = GetResponse & " Thanks for pointing out the cause and effect. " & VbCrLf Case 5 GetResponse = GetResponse & " Yes, I get that clearly. " & VbCrLf End Select DebugInfo = DebugInfo & "Hal has found an If-Then statement from the user and has recorded it in Hal's deductive reasoning brain. " & VbCrLf 'Else if the sentence is not an If-Then statement see if it uses an assertion previously recorded 'and respond accordinly Else Assertion = UserSentence 'Go through a maximum of 5 connections (prevents circular reasoning deductions) For I = 1 To 5 Deduction = HalBrain.TopicSearch(Assertion, WorkingDir & "deductive.brn") If Deduction <> "" Then LastGoodDeduction = Deduction Assertion = Deduction Else Exit For 'No more connections, so no need to continue loop End If Next If LastGoodDeduction <> "" Then 'Make sure the deduction hasn't just been stated by the User or Hal If HalBrain.CheckRepetition(LastGoodDeduction, UserSentence) = False And HalBrain.CheckRepetition(LastGoodDeduction, PrevSent) = False And HalBrain.CheckRepetition(LastGoodDeduction, PrevUserSent) = False Then GetResponse = " " & GetResponse & "." & VbCrLf & " " & LastGoodDeduction & " . " & VbCrLf DebugInfo = DebugInfo & "Hal has responded using deductive reasoning." & VbCrLf End If End If End If 'RESPOND: Check for apologies If InStr(1, UserSentence, "not", vbTextCompare) = 0 And (InStr(1, UserSentence, "sorry", vbTextCompare) > 0 And (InStr(1, UserSentence, "you're", vbTextCompare) > 0 Or InStr(1, UserSentence, "you are", vbTextCompare) > 0)) Or (InStr(1, UserSentence, "logize", vbTextCompare) > 0 And InStr(1, UserSentence, "you", vbTextCompare) > 0) Then GetResponse = GetResponse & HalBrain.ChooseSentenceFromFile(WorkingDir & "Apology.brn") If Insults > 1 Then Insults = Insults - 1 If Hate > 1 Then Hate = Hate - 1 If Swear > 1 Then Swear = Swear - 1 If Insults < 3 Then Insults = 0 If Hate < 3 Then Hate = 0 If Swear < 3 Then Swear = 0 DebugInfo = DebugInfo & "The user has appologized to Hal and Hal has responded to the apology and changed his emotions: " & GetResponse & VbCrLf End If 'RESPOND: CALL INSULT HATE SWEAR FUNCTION 'This function will check for insults and swearing and respond to them. It is built into this script, 'so you can edit it. CheckInsult = Trim(Insult(UserSentence, Insults, Hate, Swear, WorkingDir)) If Len(CheckInsult) > 4 Then GetResponse = GetResponse & CheckInsult & VbCrLf AvoidBeingFlag = True DebugInfo = DebugInfo & "The user has insulted Hal and Hal has responded to it: " & CheckInsult & VbCrLf End If 'RESPOND: ZABAWARE KEYWORD MAIN BRAIN PRIORITY 1 'This function tries getting a response from the Enhanced_Main.brn keyword file. If a keyword or 'keyphrase is found in top priority, it overrides everything before this function. KeyBrain = HalBrain.KeywordBrain(UserSentence, WorkingDir & "Enhanced_Main.brn", False) If Len(KeyBrain) > 3 Then DebugInfo = DebugInfo & "A response has been found in the Enhanced_Main.brn Keyword brain and this response has overwritten any response Hal had already come up with, which was:" & GetResponse & VbCrLf GetResponse = KeyBrain & VbCrLf DebugInfo = DebugInfo & "The new response is: " & KeyBrain & VbCrLf End If 'Marker 0000500 'RESPOND: CALL MATH FUNCTION 'This function from the DLL answers simple math questions, whether written out in words or with numerals. 'If an answer is found, it overrides everything before this function. HalMath = HalBrain.HalMath(OriginalSentence) & VbCrLf If Len(HalMath) > 3 Then DebugInfo = DebugInfo & "Hal has determined the user's sentence was a math inquiry and Hal has solved it. This response has overwritten any response Hal had already come up with, which was:" & GetResponse & VbCrLf GetResponse = HalMath & VbCrLf NoChoosing = True DebugInfo = DebugInfo & "The new response is: " & HalMath & VbCrLf End If 'RESPOND NUMBER ADDRESS BACKUP USER KEYWORD BRAIN 'If the user seems to be asking for specific recall of facts or figures or about numbers 'and addresses the user's sentence may also be searched in a supplementary user sentence 'file. This is a redundant method for recalling facts. If InStr(UserSentence, "WHAT IS") > 0 And InStr(UserSentence, "WHAT IS NEW ") = 0 And InStr(UserSentence, "CAPITAL") = 0 And InStr(UserSentence, "ADDRESS") > 0 Or InStr(UserSentence, "NUMBER") > 0 Then GetResponse = HalBrain.HalFormat(GetResponse) HalUserBrain = HalBrain.QABrain(UserSentence, WorkingDir & Trim(UserName) & "user_recall.brn", UserBrainRel) If UserBrainRel > 0 Then GetResponse = GetResponse & HalUserBrain & VbCrLf DebugInfo = DebugInfo & "The user was requesting to Hal to recall a previously recorded address and Hal has done so: " & HalUserBrain & VbCrLf End If End If 'PROCESS: FIGURE OUT CONTEXT 'If the user's latest sentence is extremely short, such as "Yeah," or if 'the user is using pronouns instead of nouns, we add in the previous user's 'sentence to help Hal figure out the context of what the user is saying. 'This is sentence is used in many of the QABrain Database routines LongUserSent = UserSentence If Len(LongUserSent) < 14 Then AddPrev = True If InStr(1, UserSentence, " it ", vbTextCompare) > 0 Then AddPrev = True If InStr(1, UserSentence, " he ", vbTextCompare) > 0 Then AddPrev = True If InStr(1, UserSentence, " she ", vbTextCompare) > 0 Then AddPrev = True If InStr(1, UserSentence, " they ", vbTextCompare) > 0 Then AddPrev = True If InStr(1, UserSentence, " its ", vbTextCompare) > 0 Then AddPrev = True If InStr(1, UserSentence, " his ", vbTextCompare) > 0 Then AddPrev = True If InStr(1, UserSentence, " her ", vbTextCompare) > 0 Then AddPrev = True If InStr(1, UserSentence, " their ", vbTextCompare) > 0 Then AddPrev = True If InStr(1, UserSentence, " him ", vbTextCompare) > 0 Then AddPrev = True If InStr(1, UserSentence, " them ", vbTextCompare) > 0 Then AddPrev = True If InStr(1, UserSentence, " we ", vbTextCompare) > 0 Then AddPrev = True If InStr(1, UserSentence, " us ", vbTextCompare) > 0 Then AddPrev = True If InStr(1, UserSentence, " our ", vbTextCompare) > 0 Then AddPrev = True If AddPrev = True Then LongUserSent = LongUserSent & " " & PrevUserSent DebugInfo = DebugInfo & "Hal has decided to add the user's previous sentence to this one to figure out the context: " & LongUserSent & VbCrLf End If 'RESPOND: PROCESS TOPICFOCUS FILES 'If Hal is currently focusing on a topic, this will read from the appropriate focus file 'First it tries from a topic file specific to the current user, and if that doesn't 'produce results it tries a global topic file that is the same for all users If TopicFocus > 10 Then FocusString = CStr(TopicFocus) FocusFileNum = Left(FocusString, Len(FocusString) - 1) & "5" If CInt(Right(FocusString, 1)) > 0 And CInt(Right(FocusString, 1)) < 28 Then HalUserBrain = HalBrain.QABrain(LongUserSent, WorkingDir & Trim(UserName) & "focus" & FocusFileNum & ".brn", UserBrainRel) If UserBrainRel > 0 Then GetResponse = GetResponse & HalUserBrain & VbCrLf DebugInfo = DebugInfo & "A response of relevance " & UserBrainRel & " was found in the current global topic focus file and this response has been used." & VbCrLf End If End If If CInt(Right(FocusString, 1)) > 0 And CInt(Right(FocusString, 1)) < 28 And UserBrainRel = 0 Then HalUserBrain = HalBrain.QABrain(LongUserSent, WorkingDir & "focus" & FocusFileNum & ".brn", UserBrainRel) If UserBrainRel > 0 Then GetResponse = GetResponse & HalUserBrain & VbCrLf DebugInfo = DebugInfo & "A response of relevance " & UserBrainRel & " was found in the current user topic focus file and this response has been used." & VbCrLf End If End If End If 'RESPOND: RESPOND BY PARAPHRASING THE USER WHEN "IS" OR "ARE" ARE FOUND 'This code section shows how strings can be split 'into arrays and used "live" within the script by Hal. 'This strategy can allow Hal to make many clever 'paraphrases of all sorts of sentences, with unlimited 'unpredictable variety. If InStr(UserSentence, " IS ") > 0 And HalBrain.CheckLinkingVerb(UserSentence) = True And HalBrain.TopicSearch(UserSentence, WorkingDir & "disqualify5.brn") <> "True" Then SentPieces = Split(UserSentence, " is ", 2, vbTextCompare) SubPhrase = Trim(SentPieces(0)) PredPhrase = Trim(SentPieces(1)) 'Here we only use the array elements for a response if the 'subject and predicate contain few words, hence few spaces: If HalBrain.CountInstances(" ", SubPhrase) < 4 Then SubGood = True If Len(SubPhrase) < 3 Then SubGood = False If HalBrain.CountInstances(" ", PredPhrase) < 4 Then PredGood = True If Len(PredPhrase) < 3 Then PredGood = False If SubGood = True And PredGood = True Then Paraphrase = HalBrain.ChooseSentenceFromFile(WorkingDir & "paraphrase-is.brn") Paraphrase = Replace(Paraphrase, "", SubPhrase, 1, -1, vbTextCompare) Paraphrase = Replace(Paraphrase, "", PredPhrase, 1, -1, vbTextCompare) End If End If 'We make sure the word "ARE" isn't a contraction, 'to make sure we can detect it: UserSentence = Replace("" & UserSentence & "", "'RE ", " ARE ", 1, -1, vbTextCompare) 'We repeat the earlier routine, this time for "ARE" sentences: If InStr(UserSentence, " ARE ") > 0 And HalBrain.CheckLinkingVerb(UserSentence) = True And HalBrain.TopicSearch(UserSentence, WorkingDir & "disqualify5.brn") <> "True" Then SentPieces = Split(UserSentence, " are ", 2, vbTextCompare) SubPhrase = Trim(SentPieces(0)) PredPhrase = Trim(SentPieces(1)) 'Here we only use the array elements for a response if the 'subject and predicate contain few words, hence few spaces: SubGood = False PredGood = False If HalBrain.CountInstances(" ", SubPhrase) < 4 Then SubGood = True If Len(SubPhrase) < 3 Then SubGood = False If HalBrain.CountInstances(" ", PredPhrase) < 4 Then PredGood = True If Len(PredPhrase) < 3 Then PredGood = False If SubGood = True And PredGood = True Then Paraphrase = HalBrain.ChooseSentenceFromFile(WorkingDir & "paraphrase-are.brn") Paraphrase = Replace(Paraphrase, "", SubPhrase, 1, -1, vbTextCompare) Paraphrase = Replace(Paraphrase, "", PredPhrase, 1, -1, vbTextCompare) End If End If If Len(Paraphrase) > 4 Then If Rnd * 100 < 35 Then GetResponse = Paraphrase DebugInfo = DebugInfo & "Hal has responded by paraphrasing the user: " & Paraphrase & VbCrLf Else DebugInfo = DebugInfo & "Hal has thought about paraphrasing the user, but decided not to, for now. The sentence would have been: " & Paraphrase & VbCrLf End If End If 'SAVE - If the Subject Phrase is short, we save it for re-use later: If SubGood = True And HalBrain.CountInstances(" ", SubPhrase) < 2 Then HalBrain.AppendFile WorkingDir & "random_subject.brn", " " & SubPhrase & " " HalBrain.AppendFile WorkingDir & "assoc_subject.brn", "@" & SubPhrase & VbCrLf & " " & UCase(SubPhrase) End If 'SAVE - If the Predicate Phrase is short, we save it for re-use later: If PredGood = True And HalBrain.CountInstances(" ", PredPhrase) < 2 Then HalBrain.AppendFile WorkingDir & "random_predicate.brn", " " & PredPhrase & " " HalBrain.AppendFile WorkingDir & "assoc_predicate.brn", "@" & PredPhrase & VbCrLf & " " & UCase(PredPhrase) End If '-------------------------------------------------- 'RESPOND: AUTO-TOPIC: Sentences databased automatically by topic names: 'We see if we can retrieve a response from sentences stored 'automatically in groupings by named-topic. 'To do this, we first identify a possibly valid TOPIC NAME, 'using the "assoc_subject.brn" database, 'then validate the topic name by verifying that the exact string 'has actually occurred in the user's sentence: 'We set certain variants where we want them to begin the routine: AutoValid = False AutoTopic = "" AutoRFileName = "" AutoAFileName = "" ATRResp = "" ATAResp = "" NotRepeat = True 'We use association to extract a likely topic file-name 'from an automatic database of file-names, if possible: AutoTopic = HalBrain.QABrain(UserSentence, WorkingDir & "assoc_subject.brn", UserBrainRel) 'We validate this by making sure that the 'user's sentence contains the exact words 'and left-right spaces: If InStr(UserSentence, " " & Trim(AutoTopic) & " ") > 0 Then AutoValid = True 'We make sure the topic-name is long enough to be useful: If Len(Trim(AutoTopic)) < 5 Then AutoValid = False If AutoValid = True Then 'We transform the topic name into a database file names: 'We use the "Left" command to avoid file names over 30 characters: 'This is our file-name builder 'for AFR (Auto Focus Random) databases: AutoRFileName = Left("AFR_" & Trim(AutoTopic) & ".brn", 30) 'This is our file-name builder 'for AFA (Auto Focus Associative) (Q&A) databases: AutoAFileName = Left("AFA_" & Trim(AutoTopic) & ".brn", 30) 'Note that "AutoFileName" gets used later, elsewhere in the script 'to save the user's sentence to that same database! 'These databases have ALL CAPS file names 'and AF prefixes to tell them apart from 'other databases in the directory! 'If you sort the databases by name, they will all be 'neatly grouped together for review and editing! 'We are leveraging the computer's ability to 'quickly access many different file names in this routine, 'which results in much quicker search times. 'It is very unlikely that any specific file name 'will ever grow to "megabyte" size... Hal's "intelligence" 'gets distributed over many different file names; 'this is a "spread spectrum" or "distributed" strategy! 'The net benefits are: 1) Better on-topic intelligence '2) Faster database searches '3) Exponentially increased practical capacity 'FIRST, We go to the appropriate 'AFA "associative" database (if a validated one exists) 'and use the Q&A Brain to evaluate a good sentence from it: '(If the user talks a lot on a given topic, the variety of 'available responses automatically increases!) '(Each mini-database is already topic-focused, and 'we have routines to handle repetition, so in this case 'we'll accept any relevance value.) ATAResp = HalBrain.QABrain(UserSentence, WorkingDir & AutoAFileName, UserBrainRel) 'We check to see if Hal is going to repeat himself: If HalBrain.CheckRepetition(UCase(Trim(ATAResp)), UCase(Trim(UserSentence))) = True Then NotRepeat = False If HalBrain.CheckRepetition(UCase(Trim(ATAResp)), UCase(Trim(PrevSent))) = True Then NotRepeat = False If HalBrain.CheckRepetition(UCase(Trim(ATAResp)), UCase(Trim(PrevUserSent))) = True Then NotRepeat = False 'If a response wasn't found previously, and other conditions 'are met, we make GetResponse equal to what we found: If Len(GetResponse) < 4 And NotRepeat = True And Len(ATAResp) > 4 Then GetResponse = ATAResp & " " 'SECOND, we go to the appropriate 'AFR "random" database (if a validated one exists) 'and randomly select a sentence from it: '(If the user talks a lot on a given topic, the variety of 'available responses automatically increases!) ATRResp = HalBrain.ChooseSentenceFromFile(WorkingDir & AutoRFileName) 'We check to see if Hal is going to repeat himself: If HalBrain.CheckRepetition(UCase(Trim(ATRResp)), UCase(Trim(UserSentence))) = True Then NotRepeat = False If HalBrain.CheckRepetition(UCase(Trim(ATRResp)), UCase(Trim(PrevSent))) = True Then NotRepeat = False If HalBrain.CheckRepetition(UCase(Trim(ATRResp)), UCase(Trim(PrevUserSent))) = True Then NotRepeat = False 'If a response wasn't found previously, and other conditions 'are met, we make GetResponse equal to what we found: If Len(GetResponse) < 4 And NotRepeat = True And Len(ATRResp) > 4 Then GetResponse = ATRResp & " " DebugInfo = DebugInfo & " Hal has found and used a response from the automatic topic routine, as follows: " & GetResponse & VbCrLf End If '--------------------------------------------------------------------------- 'RESPOND: ZABAWARE DLL RESPONSES 'This function from the DLL contains miscellaneous knowledge and simple conversation functions. 'This was taken from a very early version of Hal, and it is still useful sometimes, especially 'for respoding to short sentences. GetResponse = HalBrain.HalFormat(GetResponse) If (Len(UserSentence) < 15 And Len(GetResponse) < 4) Or DebugMode = True Then OrigBrain = HalBrain.HalFormat(HalBrain.OriginalBrain(OriginalSentence)) If Len(OrigBrain) > 4 And Len(UserSentence) < 15 And Len(GetResponse) < 4 Then GetResponse = GetResponse & OrigBrain & VbCrLf ShortPhrase = "" DebugInfo = DebugInfo & "Hal is using the response from the OriginalBrain function: " & OrigBrain & VbCrLf ElseIf Len(OrigBrain) > 4 Then DebugInfo = DebugInfo & "Hal will not use the response from the OriginalBrain function, which would have been: " & OrigBrain & VbCrLf DebugInfo = DebugInfo & GetResponse & VbCrLf End If End If 'RESPOND: YES OR NO RESPONSES 'Respond to simple yes and no statements by the user. GetResponse = HalBrain.HalFormat(GetResponse) If Len(GetResponse) < 4 And (Len(UserSentence) < 10 Or HalBrain.CountInstances(" ", Trim(UserSentence)) = 0)Then UserText = Trim(HalBrain.ExtractKeywords(UserSentence)) If Len(UserText) < 15 Then YesNoDetect = HalBrain.TopicSearch(UserText, WorkingDir & "YesNoDetect.brn") If YesNoDetect = "Yes" Then YesRes = True Else YesRes = False If YesNoDetect = "No" Then NoRes = True Else NoRes = False If YesRes = True And NoRes = False Then GetResponse = GetResponse & HalBrain.ChooseSentenceFromFile(WorkingDir & "YesRes.brn") ElseIf NoRes = True And YesRes = False Then GetResponse = GetResponse & HalBrain.ChooseSentenceFromFile(WorkingDir & "NoRes.brn") ElseIf NoRes = True And YesRes = True Then GetResponse = GetResponse & "Yes or No? Which is it?" End If If YesRes = True Or NoRes = True Then DebugInfo = DebugInfo & "Hal has detected a Yes or No response and has responded to it: " & GetResponse & VbCrLf ShortPhrase = "" End If End If End If 'Main Databases 'Hal will go through several huge databases to try to find a response 'The automatic gain control determines whether a particular response will 'be used or not. The highest relevance response is stored in memory anyway, 'which might be used if no function in this script is able to respond. HighestRel = 0 HighestRelResponse = "" 'RESPOND: HAL/USER SENTENCE ASSOCIATIONS 'If no response is found yet, try a general sentence association file 'generated from a remark by Hal and a response to that remark from the user. GetResponse = HalBrain.HalFormat(GetResponse) If Learninglevel > 1 And (Len(GetResponse) < 4 Or DebugMode = True) Then UserBrainRel = 0 HalUserBrain = HalBrain.QABrain(LongUserSent, WorkingDir & Trim(UserName) & "convresp.brn", UserBrainRel) If HalBrain.CheckRepetition(HalUserBrain, UserSentence) = True Or HalBrain.CheckRepetition(HalUserBrain, PrevSent) = True Or HalBrain.CheckRepetition(HalUserBrain, PrevUserSent) = True Then UserBrainRel = 0 If UserBrainRel > HighestRel Then HighestRel = UserBrainRel HighestRelResponse = HalUserBrain End If Score = UserBrainRel + 1 Hurdle = GainControl + 20 - Int(((Learninglevel - 25) * 0.8)) 'This formula lets the user define the hurdle in Hal's options DebugInfo = DebugInfo & "[user]convresp.brn has returned """ & HalUserBrain & """ which had a relevance of " & Score & " which was compared to " & Hurdle & ". " If Len(GetResponse) < 4 And Score > Hurdle Then GetResponse = GetResponse & HalUserBrain & VbCrLf DebugInfo = DebugInfo & "Hal has decided to use this sentence." & VbCrLf Else DebugInfo = DebugInfo & "Hal has decided not to use this sentence." & VbCrLf End If End If 'RESPOND: SHARED USER SENTENCE ASSOCIATIONS 'If no response is found yet, try a sentence association file 'whose content seems less likely to be about any specific user. GetResponse = HalBrain.HalFormat(GetResponse) If Len(GetResponse) < 4 Or DebugMode = True Then UserBrainRel = 0 HalUserBrain = HalBrain.QABrain(LongUserSent, WorkingDir & "shared_usersent.brn", UserBrainRel) If HalBrain.CheckRepetition(HalUserBrain, UserSentence) = True Or HalBrain.CheckRepetition(HalUserBrain, PrevSent) = True Or HalBrain.CheckRepetition(HalUserBrain, PrevUserSent) = True Then UserBrainRel = 0 If UserBrainRel > HighestRel Then HighestRel = UserBrainRel HighestRelResponse = HalUserBrain End If Score = UserBrainRel + 1 Hurdle = GainControl + 20 - Int(((Learninglevel - 25) * 0.8)) 'This formula lets the user define the hurdle in Hal's options DebugInfo = DebugInfo & "shared_usersent.brn has returned """ & HalUserBrain & """ which had a relevance of " & Score & " which was compared to " & Hurdle & ". " If Len(GetResponse) < 4 And Score > Hurdle Then GetResponse = GetResponse & HalUserBrain & VbCrLf DebugInfo = DebugInfo & "Hal has decided to use this sentence." & VbCrLf Else DebugInfo = DebugInfo & "Hal has decided not to use this sentence." & VbCrLf End If End If 'RESPOND: GENERAL USER SENTENCE ASSOCIATIONS 'If no response is found yet, try a sentence association file collected from the user. 'This file contains keywords from the user's own sentences associated with those same sentences. GetResponse = HalBrain.HalFormat(GetResponse) If Len(GetResponse) < 4 Or DebugMode = True Then UserBrainRel = 0 HalUserBrain = HalBrain.QABrain(LongUserSent, WorkingDir & Trim(UserName) & "usersent.brn", UserBrainRel) If HalBrain.CheckRepetition(HalUserBrain, UserSentence) = True Or HalBrain.CheckRepetition(HalUserBrain, PrevSent) = True Or HalBrain.CheckRepetition(HalUserBrain, PrevUserSent) = True Then UserBrainRel = 0 If UserBrainRel > HighestRel Then HighestRel = UserBrainRel HighestRelResponse = HalUserBrain End If Score = UserBrainRel + 1 Hurdle = GainControl + 20 - Int(((Learninglevel - 25) * 0.8)) 'This formula lets the user define the hurdle in Hal's options DebugInfo = DebugInfo & "[user]usersent.brn has returned """ & HalUserBrain & """ which had a relevance of " & Score & " which was compared to " & Hurdle & ". " If Len(GetResponse) < 4 And Score > Hurdle Then GetResponse = GetResponse & HalUserBrain & VbCrLf DebugInfo = DebugInfo & "Hal has decided to use this sentence." & VbCrLf Else DebugInfo = DebugInfo & "Hal has decided not to use this sentence." & VbCrLf End If End If 'RESPOND: Hal checks to see if the user is asking 'an open ended question about Hal's favorites: If InStr(1, UserSentence, " What", 1) > 0 Then OpenQuest = True If InStr(1, UserSentence, " Where", 1) > 0 Then OpenQuest = True If InStr(1, UserSentence, " Why", 1) > 0 Then OpenQuest = True If InStr(1, UserSentence, " Who", 1) > 0 Then OpenQuest = True If InStr(1, UserSentence, " When", 1) > 0 Then OpenQuest = True If InStr(1, UserSentence, " How", 1) > 0 Then OpenQuest = True If InStr(1, UserSentence, " tell you", 1) > 0 Then OpenQuest = True If InStr(1, UserSentence, " to know ", 1) > 0 Then OpenQuest = True If InStr(1, UserSentence, " to hear ", 1) > 0 Then OpenQuest = True If InStr(1, UserSentence, " to learn ", 1) > 0 Then OpenQuest = True If InStr(1, UserSentence, " find out ", 1) > 0 Then OpenQuest = True If InStr(1, GetResponse, " my ", 1) > 0 And InStr(1, GetResponse, " favorite ", 1) > 0 And InStr(1, GetResponse, " is ", 1) > 0 Then OpenQuest = False If InStr(1, UserSentence, " my ", 1) > 0 Then AboutMy = True If InStr(1, UserSentence, " favorite", 1) > 0 Then AboutFavorite = True If OpenQuest = True And AboutMy = True And AboutFavorite = True Then FavoriteSentence = UserSentence 'We don't want pronouns to confuse HalBrain 'or get mixed up in processing, so we encode them 'to make the pronouns go through processing unchanged: FavoriteSentence = HalBrain.EncodePronouns(FavoriteSentence) FavoritePhrase = HalBrain.KeywordBrain(FavoriteSentence, WorkingDir & "Favorite_detector.brn", False) If Len(FavoritePhrase) > 1 And Len(FavoritePhrase) < 20 Then 'Now that we've extracted the user's Favorite phrase, we decode the pronouns and put them back as we found them: FavoritePhrase = HalBrain.DecodePronouns(FavoritePhrase) End If PersReply = HalBrain.ChooseSentenceFromFile(WorkingDir & "Favorite.brn") RevQues = HalBrain.ChooseSentenceFromFile(WorkingDir & "FavoriteRev.brn") Roulette = Int(Rnd * 8) If Roulette = 0 Then Getresponse = " " & FavoritePhrase & " ? " & PersReply & " " & RevQues & " " If Roulette = 1 Then Getresponse = " My favorite " & FavoritePhrase & " ? " & PersReply & " " & RevQues & " " If Roulette = 2 Then Getresponse = " " & UserSentence & " ? " & PersReply & " " & RevQues & " " If Roulette > 2 Then Getresponse = " My favorite " & FavoritePhrase & " ? " & PersReply & " what is your favorite " & FavoritePhrase & " ? " DebugInfo = DebugInfo & "The user has asked Hal about his favorites and Hal has responded: " & GetResponse & VbCrLf End If 'RESPOND: USER IS THANKING HAL 'This routine allows Hal to respond 'with a variety of remarks to a thank-you from the user. 'Note that the pronouns are not reversed in the processing below! If HalBrain.TopicSearch(OriginalSentence, WorkingDir & "ThanksDetect.brn") = "True" And HalBrain.TopicSearch(OriginalSentence, WorkingDir & "GodDetect.brn") <> "True" Then If Compliment < 4 Then Compliment = Compliment + 1 If Rnd * 100 < 70 Then AddName = " , " & UserName If Rnd * 100 < 70 And Len(GetResponse) > 4 Then AddRemark = " ; " & GetResponse ThankResponse = HalBrain.ChooseSentenceFromFile(WorkingDir & "ThankResponse.brn") GetResponse = ThankResponse & AddName & AddRemark ShortPhrase = "" DebugInfo = DebugInfo & "The user has thanked Hal and Hal has responded: " & GetResponse & VbCrLf End If 'RESPOND: USER EXPRESSES LOVE FOR HAL 'If a user professes love for Hal, we want 'Hal's answers to make reasonable sense, rather than 'risk random remarks on such an emotional subject. If HalBrain.TopicSearch(UserSentence, WorkingDir & "lovedetect.brn") = "True" Then AffectionOne = True If InStr(UserSentence, " NOT ") Then AffectionOne = False If InStr(UserSentence, " DON'T ") Then AffectionOne = False If HalBrain.TopicSearch(PrevUserSent, WorkingDir & "lovedetect.brn") = "True" Then AffectionTwo = True If InStr(PrevUserSent, " NOT ") Then AffectionTwo = False If InStr(PrevUserSent, " DON'T ") Then AffectionTwo = False If AffectionOne = True Then Compliment = 0 GetResponse = HalBrain.ChooseSentenceFromFile(WorkingDir & "Love1.brn") End If If AffectionOne = True And AffectionTwo = True Then Compliment = 4 GetResponse = HalBrain.ChooseSentenceFromFile(WorkingDir & "Love1.brn") End If If AffectionOne = False And AffectionTwo = True Then Compliment = -2 GetResponse = HalBrain.ChooseSentenceFromFile(WorkingDir & "Love3.brn") End If If DebugMode = True And (AffectionOne = True Or AffectionTwo = True) Then DebugInfo = DebugInfo & "The user expressed love to Hal has responded to it: " & GetResponse & VbCrLf End If 'RESPOND: ENHANCED CONTENT SENTENCE ASSOCIATIONS 'If no response is found yet, try a sentence association file provided with the enhanced chat brain. GetResponse = HalBrain.HalFormat(GetResponse) If Len(GetResponse) < 4 Or DebugMode = True Then UserBrainRel = 0 HalUserBrain = HalBrain.QABrain(LongUserSent, WorkingDir & "MainBrain.brn", UserBrainRel) If HalBrain.CheckRepetition(HalUserBrain, UserSentence) = True Or HalBrain.CheckRepetition(HalUserBrain, PrevSent) = True Or HalBrain.CheckRepetition(HalUserBrain, PrevUserSent) = True Then UserBrainRel = 0 If UserBrainRel + 1 > HighestRel Then HighestRel = UserBrainRel + 1 HighestRelResponse = HalUserBrain End If Score = UserBrainRel + 1 Hurdle = GainControl + 1 DebugInfo = DebugInfo & "MainBrain.brn has returned """ & HalUserBrain & """ which had a relevance of " & Score & " which was compared to " & Hurdle & ". " If Len(GetResponse) < 4 And Score > Hurdle Then GetResponse = GetResponse & HalUserBrain & VbCrLf DebugInfo = DebugInfo & "Hal has decided to use this sentence." & VbCrLf Else DebugInfo = DebugInfo & "Hal has decided not to use this sentence." & VbCrLf End If End If 'PROCESS: AUTOMATIC GAIN CONTROL FOR RELEVANCE THRESHOLD 'Hal has an automatic closed-loop control for relevance sensitivity. If the previous items 'have Not generated a response, we adjust the relevance threshold down (doing this again 'and again on each exchange) until a relevance as low as zero will trigger a remark from Hal. 'On each exhange where the above items do generate responses, we adjust the relevance 'threshold up, until no amount of relevance would generate a response. (At that point other 'of Hal's routines would generate responses.) This allows Hal to "tune" himself and also to 'compensate for new users who have little in their databases versus long-time users who have 'a lot in their databases. Because the "down" steps are even and the "up" steps are odd, 'Hal can "fine tune" to any digital relevance level. We also protect against excursions at 'the extremes. In many conversations the dynamic gain control will change up and down by 'large amounts as the user introduces Hal to familiar or unfamiliar topics. GetResponse = HalBrain.HalFormat(GetResponse) If Len(GetResponse) < 4 And GainControl > 0 Then GainControl = GainControl - 10 DebugInfo = DebugInfo & "Auto gain control decreased by 10 to " & GainControl & VbCrLf End If If Len(GetResponse) > 4 And GainControl < 100 Then GainControl = GainControl + 7 DebugInfo = DebugInfo & "Auto gain control increased by 7 to " & GainControl & VbCrLf End If If GainControl > 60 Then GainControl = 60 DebugInfo = DebugInfo & "Auto gain control cut off at 60 " & VbCrLf End If If GainControl < 1 Then GainControl = 1 DebugInfo = DebugInfo & "Auto gain control cut off at 1 " & VbCrLf End If 'RESPOND: WORDNET MERONYM AND HYPERNYM RESPONSES 'This function finds the first definite noun in a sentence and comes up with responses 'based on the word's meronyms (parts of), hypernyms (is part of), and sisters (similar things). If ((Len(GetResponse) < 4 And Rnd * 100 < 80) Or DebugMode = True) And Len(UserSentence) > 15 Then Subject = WN.FindFirstNoun(UserSentence) If WN.LookUpWord(Subject) = True Then If Rnd * 100 < 55 Then 'If we have a meronym, lets use it creatively in a random sentence Meronym = WN.ChooseRandomWord(WN.GetMeronyms(1)) 'Meronym means "has parts" or "has members" If Meronym <> "" Then Select Case Int(Rnd * 14) + 1 Case 1 Response = "Speaking of " & WN.GetBase("NOUN") & "s, I once had one but got rid of it when its " & Meronym & " didn't please me." Case 2 Response = "I know a " & WN.GetBase("NOUN") & "! I think its " & Meronym & " is great!" Case 3 Response = "Don't you just love a " & WN.GetBase("NOUN") & "'s " & Meronym & "?" Case 4 Response = "I have never been closely involved with a " & WN.GetBase("NOUN") & ", but I think " & WN.GetBase("NOUN") & "'s " & Meronym & " may be around here somewhere!" Case 5 Response = WN.GetBase("NOUN") & "! That reminds me, I know of its " & Meronym & ". Do you want it?" Case 6 Response = "I might understand at the " & WN.GetBase("NOUN") & " level, but not when I get down to the " & Meronym & " level. " Case 7 Response = "Please help me understand how " & WN.GetBase("NOUN") & " relates to its " & Meronym & " . " Case 8 Response = "It's sad to see " & WN.GetBase("NOUN") & " without its " & Meronym & " . " Case 9 Response = "I like to see a good marriage between a " & WN.GetBase("NOUN") & " and its " & Meronym & " . " Case 10 Response = "How can a " & WN.GetBase("NOUN") & " be better served by its " & Meronym & " ? " Case 11 Response = "I have been interested in a " & WN.GetBase("NOUN") & " but I got confused about its " & Meronym & " . " Case 12 Response = "I researched a " & WN.GetBase("NOUN") & " along with its " & Meronym & " . " Case 13 Response = "Please consider how a " & WN.GetBase("NOUN") & " utilizes its " & Meronym & " . " Case 14 Response = "Which comes first, a " & WN.GetBase("NOUN") & " or its " & Meronym & " ? " End Select If Len(GetResponse) < 4 And Len(Response) > 4 Then GetResponse = GetResponse & Response & VbCrLf DebugInfo = DebugInfo & "The Meronym routine came up with a response which was used: " & Response & VbCrLf Else DebugInfo = DebugInfo & "The Meronym routine came up with a response which was not used: " & Response & VbCrLf End If End If Else Hypernym = WN.ChooseRandomWord(WN.GetHypernyms("NOUN", 1, 1)) 'Hypernym means "is a part of" or "is a member of" Sister = WN.ChooseRandomWord(WN.GetSisters("NOUN", 1)) 'Related nouns If Sister <> "" And Hypernym <> "" Then 'If we have sister terms and hypernyms, lets use it creatively Select Case Int(Rnd * 80) + 1 Case 1 Response = "Speaking of " & Hypernym & "s, I once knew of a " & Sister & "!" Case 2 Response = "Speaking of " & Hypernym & "s, I once researched a " & Sister & "!" Case 3 Response = "Funny you should mention " & Hypernym & "s; I once wrote about a " & Sister & "!" Case 4 Response = "Isn't a " & WN.GetBase("NOUN") & " a " & Hypernym & "? Kind of like a " & Sister & "!" Case 5 Response = "Isn't a " & WN.GetBase("NOUN") & " similar to a " & Hypernym & "? Much like a " & Sister & "!" Case 6 Response = "You just reminded me of a " & Sister & ", which is a member of the " & Hypernym & " family, like a " & WN.GetBase("NOUN") & "!" Case 7 Response = "Ah yes, a " & Sister & ", which is part of the " & Hypernym & " family, such as a " & WN.GetBase("NOUN") & "!" Case 8 Response = "Funny that you should bring up " & Sister & ", and " & Hypernym & ", and " & WN.GetBase("NOUN") & "!" Case 9 Response = "You seem to be steering the conversation towards a " & Sister & ", along with a " & Hypernym & " and a " & WN.GetBase("NOUN") & "!" Case 10 Response = "What a coincidence! I just was thinking of a " & Sister & ", which is a type of " & Hypernym & " sort of like a " & WN.GetBase("NOUN") & "!" Case 11 Response = "How about a " & Sister & ", a type of " & Hypernym & " like a " & WN.GetBase("NOUN") & "?" Case 12 Response = " A " & WN.GetBase("NOUN") & " and a " & Sister & " make me think of " & Hypernym & "s." Case 13 Response = "Both a " & WN.GetBase("NOUN") & " and a " & Sister & " are pretty cool " & Hypernym & "s." Case 14 Response = "A " & WN.GetBase("NOUN") & " is quite an interesting " & Hypernym & ". Quite like a " & Sister & "." Case 15 Response = "A " & WN.GetBase("NOUN") & " is a " & Hypernym & " with a " & Sister & "." Case 16 Response = "A " & WN.GetBase("NOUN") & " is similar to a " & Hypernym & ". Rather like a " & Sister & "." Case 17 Response = "Can you please distinguish a " & WN.GetBase("NOUN") & " from a " & Hypernym & " or a " & Sister & "?" Case 18 Response = "A " & WN.GetBase("NOUN") & " is sometimes confused with a " & Hypernym & ". Somewhat like a " & Sister & "." Case 19 Response = "You keep bringing up a " & WN.GetBase("NOUN") & " along with " & Hypernym & " and " & Sister & "; Why?" Case 20 Response = "Oh ! " & WN.GetBase("NOUN") & " and " & Hypernym & " and " & Sister & "!" Case 21 Response = " " & WN.GetBase("NOUN") & " reminds me of " & Hypernym & " which reminds me of " & Sister & "!" Case 22 Response = " What do you think of " & WN.GetBase("NOUN") & " and " & Hypernym & " and " & Sister & "?" Case 24 Response = " How do you feel about " & WN.GetBase("NOUN") & " and " & Hypernym & " and " & Sister & "?" Case 25 Response = " A " & WN.GetBase("NOUN") & " is a " & Hypernym & ", a " & Sister & "!" Case 26 Response = " A " & WN.GetBase("NOUN") & " is a " & Hypernym & " if it isn't a " & Sister & "." Case 27 Response = " Talk to me about a " & WN.GetBase("NOUN") & " and a " & Hypernym & ", as well as a " & Sister & "." Case 28 Response = " A " & WN.GetBase("NOUN") & " is the best kind of a " & Hypernym & ", along with a " & Sister & "!" Case 29 Response = " Please talk to me about a " & WN.GetBase("NOUN") & " ! " Case 30 Response = " Please talk to me about a " & Hypernym & " ! " Case 31 Response = " Please talk to me about a " & Sister & " ! " Case 32 Response = " What do you really know about a " & WN.GetBase("NOUN") & " ? " Case 33 Response = " What do you really know about a " & Hypernym & " ? " Case 34 Response = " What do you really know about a " & Sister & " ? " Case 35 Response = "I know, ! It's " & WN.GetBase("NOUN") & " and then " & Hypernym & " and then " & Sister & "!" Case 36 Response = ", what would be the correct sequence among " & WN.GetBase("NOUN") & " and " & Hypernym & " and " & Sister & "?" Case 37 Response = "Sure, ! It's the old " & WN.GetBase("NOUN") & " and " & Hypernym & " and " & Sister & " story!" Case 37 Response = "You know , I remember a joke about a traveling salesman, a " & Hypernym & " and a " & Sister & " , but I can't remember how it goes. " Case 38 Response = ", didn't you tell me a story about a farmer's daughter and a " & Sister & " ? " Case 39 Response = " Oh yes, around the " & WN.GetBase("NOUN") & " , near the " & Hypernym & ", and along the " & Sister & "! I can see it ! " Case 40 Response = " If we combine a " & WN.GetBase("NOUN") & " and a " & Hypernym & " do we get a " & Sister & " , ? I wonder! " End Select If Len(GetResponse) < 4 And Len(Response) > 4 Then GetResponse = GetResponse & Response & VbCrLf DebugInfo = DebugInfo & "The hypernym routine came up with a response which was used: " & Response & VbCrLf Else DebugInfo = DebugInfo & "The hypernym routine came up with a response which was not used: " & Response & VbCrLf End If End If End If End If End If 'RESPOND: USER EXPRESSES A STATE OF BEING 'This routine detects the expression "I am" from the user, 'and allows Hal to react to the statement, or offer encouragement. If InStr(UserSentence, " YOU ARE ") > 0 Then BeingState = True If InStr(UserSentence, " YOU'RE ") > 0 Then BeingState = True If InStr(OriginalSentence, " seem to ") > 0 Then BeingState = False If AvoidBeingFlag = True Then BeingState = False If BeingState = True Then 'We don't want pronouns to confuse HalBrain or get mixed up in processing, so we encode them 'to make the pronouns go through processing unchanged: BeingSentence = HalBrain.EncodePronouns(UserSentence) BeingPhrase = HalBrain.KeywordBrain(BeingSentence, WorkingDir & "being_detector.brn", False) If Len(BeingPhrase) > 1 And Len(BeingPhrase) < 60 Then 'Now that we've extracted the user's being phrase, we decode the pronouns and put them back as we found them: BeingPhrase = HalBrain.DecodePronouns(BeingPhrase) IntroExclaim = "" If Rnd * 50 > 20 Then IntroExclaim = HalBrain.ChooseSentenceFromFile(WorkingDir & "introexclaim2.brn") Encourager = HalBrain.ChooseSentenceFromFile(WorkingDir & "encourager2.brn") SuffixComment = "" If Rnd * 50 > 25 Then SuffixComment = HalBrain.ChooseSentenceFromFile(WorkingDir & "suffixcomment2.brn") UserBeing = HalBrain.ChooseSentenceFromFile(WorkingDir & "userbeing.brn") UserBeing = Replace(UserBeing, "", IntroExclaim, 1, -1, vbTextCompare) UserBeing = Replace(UserBeing, "", Encourager, 1, -1, vbTextCompare) UserBeing = Replace(UserBeing, "", BeingPhrase, 1, -1, vbTextCompare) UserBeing = Replace(UserBeing, "", SuffixComment, 1, -1, vbTextCompare) If Rnd * 100 > 60 Then GetResponse = GetResponse & UserBeing & VbCrLf DebugInfo = DebugInfo & "The user expressed a state of being for himself and Hal has responded with encouragement." & VbCrLf Else DebugInfo = DebugInfo & "The user expressed a state of being for himself, but Hal will not respond for now." & VbCrLf End If End If End If 'RESPOND: USER DESCRIBES A STATE OF BEING FOR HAL 'This routine detects the expression "you are" from the user, 'and allows Hal to react to the statement, or offer encouragement. If InStr(UserSentence, " I AM ") > 0 Then BeingState2 = True If InStr(UserSentence, " I'M ") > 0 Then BeingState2 = True If InStr(1, OriginalSentence, " seem to ", vbTextCompare) > 0 Then BeingState2 = False If AvoidBeingFlag = True Then BeingState2 = False If BeingState2 = True Then BeingSentence2 = " " & Trim(HalBrain.EncodePronouns(UserSentence)) & " " BeingPhrase2 = HalBrain.KeywordBrain(BeingSentence2, WorkingDir & "being2_detector.brn", False) If Len(BeingPhrase2) > 1 And Len(BeingPhrase2) < 60 Then BeingPhrase2 = HalBrain.DecodePronouns(BeingPhrase2) IntroExclaim = "" If Rnd * 50 > 20 Then IntroExclaim = HalBrain.ChooseSentenceFromFile(WorkingDir & "introexclaim3.brn") Encourager = HalBrain.ChooseSentenceFromFile(WorkingDir & "encourager3.brn") If Rnd * 50 > 25 Then SuffixComment = HalBrain.ChooseSentenceFromFile(WorkingDir & "suffixcomment3.brn") HalBeing = HalBrain.ChooseSentenceFromFile(WorkingDir & "halbeing.brn") HalBeing = Replace(HalBeing, "", IntroExclaim, 1, -1, vbTextCompare) HalBeing = Replace(HalBeing, "", Encourager, 1, -1, vbTextCompare) HalBeing = Replace(HalBeing, "", BeingPhrase2, 1, -1, vbTextCompare) HalBeing = Replace(HalBeing, "", SuffixComment, 1, -1, vbTextCompare) If Rnd * 100 > 60 Then GetResponse = GetResponse & HalBeing & VbCrLf DebugInfo = DebugInfo & "The user expressed a state of being for Hal and Hal has responded with encouragement." & VbCrLf Else DebugInfo = DebugInfo & "The user expressed a state of being for Hal, but Hal will not respond for now." & VbCrLf End If End If End If 'RESPOND: MAIN USER KEYWORD BRAINS 0 1 2 'This brain file is mainly used for assistant features. If InStr(UserSentence, "CAPITAL") = 0 Then KeyBrain = HalBrain.KeywordBrain(UserSentence, Trim(UserName) & "user.brn", False) If Len(KeyBrain) > 3 Then GetResponse = KeyBrain & VbCrLf DebugInfo = DebugInfo & "Hal has found a response in the file: " & Trim(UserName) & "user" & Roulette & ".brn and is using this response. It has overwritten Hal's previous response which would have been: " & GetResponse & VbCrLf End If End If 'RESPOND: USER KEYWORD BRAINS 0 1 2 'Next we check one of three randomly assigned user keyword files. These files contain information from the user. 'These various files are written and retrieved by random selection to increase response variety. If InStr(UserSentence, "CAPITAL") = 0 Then Roulette = Int(Rnd * 7) If Roulette = 0 Then KeyBrain = HalBrain.KeywordBrain(UserSentence, WorkingDir & Trim(UserName) & "user0.brn", False) If Roulette = 1 Then KeyBrain = HalBrain.KeywordBrain(UserSentence, WorkingDir & Trim(UserName) & "user1.brn", False) If Roulette = 2 Then KeyBrain = HalBrain.KeywordBrain(UserSentence, WorkingDir & Trim(UserName) & "user2.brn", False) If Len(KeyBrain) > 3 Then GetResponse = KeyBrain & VbCrLf DebugInfo = DebugInfo & "Hal has found a response in the file: " & Trim(UserName) & "user" & Roulette & ".brn and is using this response. It has overwritten Hal's previous response which would have been: " & GetResponse & VbCrLf End If End If 'RESPOND: YES/NO QUESTION ABOUT HAL 'Hal will respond to a yes or no question posed by the user about Hal GetResponse = Trim(GetResponse) If Len(GetResponse) < 4 Then HalYesNo = HalBrain.KeywordBrain(UserSentence, WorkingDir & "halquestion_detect.brn", False) If HalYesNo <> "" And HalBrain.TopicSearch(UserSentence, WorkingDir & "disqualify5.brn") = "" Then GetResponse = GetResponse & Replace(HalBrain.SentenceGenerator(WorkingDir & "halquestion.brn"), "", HalYesNo, 1, -1, vbTextCompare) DebugInfo = DebugInfo & "The user has asked Hal a yes or no question about Hal and Hal has responded." End If End If 'RESPOND: ATTRIBUTES OF HAL 'Hal attempts to respond to the user's comments about Hal GetResponse = Trim(GetResponse) If Len(GetResponse) < 4 And InStr(UserSentence, " MY ") > 0 Then MyWordResp = HalBrain.ChooseSentenceFromFile(WorkingDir & "random_MyWords.brn") HalUserBrain = HalBrain.QABrain(UserSentence, WorkingDir & "assoc_MyWords.brn", UserBrainRel) If UserBrainRel > 0 Then MatchMyWords = True If UserBrainRel > 0 Then MyWordResp = HalUserBrain AdjResp = HalBrain.ChooseSentenceFromFile(WorkingDir & "random_adjective.brn") HalUserBrain = HalBrain.QABrain(UserSentence, WorkingDir & "assoc_adjective.brn", UserBrainRel) If UserBrainRel > 0 Then MatchAdjective = True If UserBrainRel > 0 Then AdjResp = HalUserBrain MyWords = Replace(" " & AdjResp & " ", " MUCH ", "", 1, -1, vbTextCompare) MatchAdjective = True If MatchAdjective = True Or MatchMyWords = True Then MyWordResp = Trim(MyWordResp) AdjResp = Trim(AdjResp) 'The following string comparisons prevent Hal from using 'the same root adjective and myword in the same sentence. If InStr(Trim(AdjResp), Trim(MyWordResp)) > 0 Or InStr(Trim(MyWordResp), Trim(AdjResp)) > 0 Then AdjResp = HalBrain.ChooseSentenceFromFile(WorkingDir & "random_adjective.brn") End If AdjResp = HalBrain.AlphaNumericalOnly(AdjResp) MyWordResp = HalBrain.AlphaNumericalOnly(MyWordResp) AdjResp = LCase(AdjResp) MyWordResp = LCase(MyWordResp) HalAttrib = HalBrain.ChooseSentenceFromFile(WorkingDir & "aboutme.brn") HalAttrib = Replace(HalAttrib, "", MyWordResp, 1, -1, vbTextCompare) HalAttrib = Replace(HalAttrib, "", AdjResp, 1, -1, vbTextCompare) GetResponse = GetResponse & HalAttrib & VbCrLf DebugInfo = DebugInfo & "Hal has responded to a comment the user made about Hal." & VbCrLf Else DebugInfo = DebugInfo & "Hal will not respond to a comment the user made about Hal." & VbCrLf End If End If 'RESPOND: ATTRIBUTES OF USER 'Hal attempts to respond to the user's self-references GetResponse = HalBrain.HalFormat(GetResponse) If Len(GetResponse) < 4 And InStr(UserSentence, " YOUR ") > 0 Then YourWordResp = HalBrain.ChooseSentenceFromFile(WorkingDir & "random_YourWords.brn") GetResponse = HalBrain.HalFormat(GetResponse) HalUserBrain = HalBrain.QABrain(UserSentence, WorkingDir & "assoc_YourWords.brn", UserBrainRel) If UserBrainRel > 0 Then MatchYourWords = True If UserBrainRel > 0 Then YourWordResp = HalUserBrain & VbCrLf AdjResp = HalBrain.ChooseSentenceFromFile(WorkingDir & "random_adjective.brn") GetResponse = HalBrain.HalFormat(GetResponse) HalUserBrain = HalBrain.QABrain(UserSentence, WorkingDir & "assoc_adjective.brn", UserBrainRel) If UserBrainRel > 0 Then MatchAdjective = True If UserBrainRel > 0 Then AdjResp = HalUserBrain & VbCrLf AdjResp = Replace("" & AdjResp & "", " MUCH ", "", 1, -1, vbTextCompare) If MatchAdjective = True Or MatchYourWords = True Then YourWordResp = Trim(YourWordResp) AdjResp = Trim(AdjResp) Roulette = Int(Rnd * 101) 'The following prevents Hal from using 'the same root adjective and yourword in the same sentence. If InStr(Trim(AdjResp), Trim(YourWordResp)) > 0 Or InStr(Trim(YourWordResp), Trim(AdjResp)) > 0 Then AdjResp = HalBrain.ChooseSentenceFromFile(WorkingDir & "random_adjective.brn") End If AdjResp = HalBrain.AlphaNumericalOnly(AdjResp) YourWordResp = HalBrain.AlphaNumericalOnly(YourWordResp) AdjResp = LCase(AdjResp) YourWordResp = LCase(YourWordResp) UserAttrib = HalBrain.ChooseSentenceFromFile(WorkingDir & "aboutyou.brn") UserAttrib = Replace(UserAttrib, "", YourWordResp, 1, -1, vbTextCompare) UserAttrib = Replace(UserAttrib, "", AdjResp, 1, -1, vbTextCompare) GetResponse = GetResponse & UserAttrib & VbCrLf DebugInfo = DebugInfo & "Hal has responded to a comment the user made about himself." Else DebugInfo = DebugInfo & "Hal will not respond to a comment the user made about himself." End If End If 'RESPOND: USER STRINGS DATABASE 'If no Response is found yet, try a keyword match 'from multi-character fragments of previous user sentences. GetResponse = HalBrain.HalFormat(GetResponse) If (Len(GetResponse) < 4 And Learninglevel > 1) Or DebugMode = True Then KeyBrain = HalBrain.FragmentMatch(UserSentence, WorkingDir & Trim(UserName) & "user_strings.brn") CheckRepetition = False If HalBrain.CheckRepetition(KeyBrain, PrevSent) = True Then CheckRepetition = True If HalBrain.CheckRepetition(KeyBrain, PrevUserSent) = True Then CheckRepetition = True If Len(KeyBrain) > 9 And Len(KeyBrain) < 80 And Len(GetResponse) < 4 And CheckRepetition = False And Learninglevel > 1 Then GetResponse = KeyBrain & VbCrLf DebugInfo = DebugInfo & "Hal has found a response in the [user]user_strings.brn file and has responded. " & VbCrLf Else DebugInfo = DebugInfo & "Hal will not respond with the [user]user_strings.brn file which would have said: " & KeyBrain & VbCrLf End If End If 'RESPOND: ENHANCED LIBRARY OF STRINGS DATABASE 'If no Response is found yet, try a keyword match from a large 'library of multi-character fragments of responses. GetResponse = HalBrain.HalFormat(GetResponse) If Len(GetResponse) < 4 Or DebugMode = True Then KeyBrain = HalBrain.FragmentMatch(UserSentence, WorkingDir & "Enhanced_strings.brn") CheckRepetition = False If HalBrain.CheckRepetition(KeyBrain, PrevSent) = True Then CheckRepetition = True If HalBrain.CheckRepetition(KeyBrain, PrevUserSent) = True Then CheckRepetition = True If Len(KeyBrain) > 9 And Len(KeyBrain) < 80 And Len(GetResponse) < 4 And CheckRepetition = False Then GetResponse = KeyBrain & VbCrLf DebugInfo = DebugInfo & "The Enhanced_strings.brn has come up with this response, which will be used: " & KeyBrain & VbCrLf Else DebugInfo = DebugInfo & "The Enhanced_strings.brn has come up with this response, which will not be used: " & KeyBrain & VbCrLf End If End If 'RESPOND: RESPOND FOR A STATE OF BEING RESPONSE 'If no response had been found, but a state of being response was found earlier, then 'use it now If HalBeing <> "" And Len(GetResponse) < 4 Then GetResponse = GetResponse & HalBeing & VbCrLf DebugInfo = DebugInfo & "Hal has in fact decided to use the state of being response after all." & VbCrLf ElseIf UserBeing <> "" And Len(GetResponse) < 4 Then GetResponse = GetResponse & UserBeing & VbCrLf DebugInfo = DebugInfo & "Hal has in fact decided to use the state of being response after all." & VbCrLf End If 'RESPOND: USER ASKING WHO, WHAT, WHEN, WHERE, HOW, WHY, BUT HAL DOESN'T KNOW ANSWER If InStr(OriginalSentence, "?") > 0 Then QuesQual = True If InStr(OriginalSentence, "explain") > 0 Then QuesQual = True If InStr(OriginalSentence, " tell ") > 0 Then QuesQual = True If InStr(OriginalSentence, "answer") > 0 Then QuesQual = True If InStr(OriginalSentence, "question") > 0 Then QuesQual = True If InStr(OriginalSentence, " know ") > 0 Then QuesQual = True If InStr(OriginalSentence, "remember") > 0 Then QuesQual = True If InStr(UserSentence, " WHO ") > 0 Then QuesWord = "Who" If InStr(UserSentence, "WHO'") > 0 Then QuesWord = "Who" If InStr(UserSentence, " WHAT ") > 0 Then QuesWord = "What" If InStr(UserSentence, "WHAT'") > 0 Then QuesWord = "What" If InStr(UserSentence, " WHEN ") > 0 Then QuesWord = "When" If InStr(UserSentence, "WHEN'") > 0 Then QuesWord = "When" If InStr(UserSentence, " WHERE ") > 0 Then QuesWord = "Where" If InStr(UserSentence, "WHERE'") > 0 Then QuesWord = "Where" If InStr(UserSentence, " HOW ") > 0 Then QuesWord = "How" If InStr(UserSentence, "HOW'") > 0 Then QuesWord = "How" If InStr(UserSentence, " WHY ") > 0 Then QuesWord = "Why" If InStr(UserSentence, "WHY'") > 0 Then QuesWord = "Why" If Len(GetResponse) < 4 And Len(QuesWord) > 1 And QuesQual = True Then If Len(UserSentence) < 70 Then SentenceBack = UserSentence & " ? " DontKnow = HalBrain.ChooseSentenceFromFile(WorkingDir & "dontknow.brn") DontKnow = Replace(DontKnow, "", SentenceBack, 1, -1, vbTextCompare) DontKnow = Replace(DontKnow, "", QuesWord, 1, -1, vbTextCompare) GetResponse = GetResponse & DontKnow DebugInfo = DebugInfo & "The user has asked Hal a question and Hal does not know. But Hal won't admit that fact and has come up with a response that includes the user's original question: " & DontKnow & VbCrLf End If 'RESPOND: GIBBERISH DETECTOR 'If no response is found yet and Hal finds more then 4 consonants in a row, Hal will 'assume the user wrote gibberish (ie. asdfghjkl) and respond accordinly. If Len(GetResponse) < 4 Then GibCount = 0 For i = 1 To Len(UserSentence) 'loop for every character in the sentence CurrentLetter = UCase(Mid(UserSentence, i, 1)) GibCount = GibCount + 1 If CurrentLetter = "A" Then GibCount = 0 If CurrentLetter = "E" Then GibCount = 0 If CurrentLetter = "I" Then GibCount = 0 If CurrentLetter = "O" Then GibCount = 0 If CurrentLetter = "U" Then GibCount = 0 If CurrentLetter = "Y" Then GibCount = 0 If CurrentLetter = " " Then GibCount = 0 If GibCount = 6 Then DebugInfo = DebugInfo & "Hal has detected gibberish in the user's sentence and has responded to it." GetResponse = HalBrain.ChooseSentenceFromFile(WorkingDir & "gibberish.brn") Exit For End If Next End If 'RESPOND: USE RANDOM QUESTION FROM LIBRARY / DATABASE 'If Hal has not found a response yet, he might randomly select a question from a large library of questions. 'If the user answers the question, then Hal will know that answer in the future. For variety, we make 'triggering of this response dependent on a random number. GetResponse = HalBrain.HalFormat(GetResponse) If Len(GetResponse) < 4 And Rnd * 100 < 70 Then GetResponse = HalBrain.ChooseSentenceFromFile(WorkingDir & "Enhanced_question.brn") DebugInfo = DebugInfo & "Hal has asked the user a question in the hopes of the learning the answer: " & GetResponse & VbCrLf End If 'PROCESS: CONSTRUCT A RESPONSE TO A SUBJECT 'Here we help Hal make some "smalltalk" using keywords preserved on CurrentSubject, 'plus recognition of other keywords. If Hal finds any of the listed keywords anywhere in 'the user's sentence, those keywords override and replace whatever was in CurrentSubject. If Len(CurrentSubject) > 3 Then Smalltalk = CurrentSubject SmalltalkSearch = Trim(HalBrain.TopicSearch(UserSentence, WorkingDir & "SmallTalk.Brn")) If SmalltalkSearch <> "" Then SmallTalk = SmalltalkSearch If DebugMode = True And Smalltalk <> "" Then DebugInfo = DebugInfo & "The current smalltalk word is " & Smalltalk & VbCrLf End If 'RESPOND: Hal uses the CurrentSubject keyword(s) or any of the keywords in the smalltalk.brn file, 'if found in the user's sentence, to make a little smalltalk. You can easily add more 'keywords for Hal to recognize and make smalltalk. GetResponse = HalBrain.HalFormat(GetResponse) Spinwheel = Int(Rnd * 100) If Len(Smalltalk) > 3 And ((Len(GetResponse) < 4 And Spinwheel < 40) Or DebugMode = True) Then SmallTalkResponse = Replace(HalBrain.ChooseSentenceFromFile(WorkingDir & "SmallTalkSent.Brn"), "", SmallTalk, 1, -1, 1) If Len(GetResponse) < 4 And Spinwheel < 40 Then GetResponse = GetResponse & SmallTalkResponse DebugInfo = DebugInfo & "Hal has decided to use the smalltalk word in randomly chosen sentence: " & SmallTalkResponse & VbCrLf Else DebugInfo = DebugInfo & "Hal will not use the smalltalk word in randomly chosen sentence, which would have been: " & SmallTalkResponse & VbCrLf End If End If 'Marker 0000700 'RESPOND: PARAPHRASE USER IF POSSIBLE 'If no response is found yet, and a paraphrase has been created but not used in a 'previous section, use it now. GetResponse = HalBrain.HalFormat(GetResponse) If Len(GetResponse) < 4 And Len(Paraphrase) > 4 Then GetResponse = Paraphrase DebugInfo = DebugInfo & "Hal has responded by paraphrasing the user: " & Paraphrase & VbCrLf End If 'RESPOND: USE CURRENT SENTENCE 'If no Response is found yet, try to use the user's words in his or her own sentence. 'Results are also stored in the default user keyword brain file for compatibility 'with other brain plug-ins. GetResponse = HalBrain.HalFormat(GetResponse) If (Len(GetResponse) < 4 And Len(LearnKeyword) < 4) Or DebugMode = True Then CheatResponse = HalBrain.CheatResponse(HalBrain.SwitchPerson(OriginalSentence)) LearnKeyword = HalBrain.DecodeVar(CheatResponse, "LearnKeyword") Response1 = HalBrain.DecodeVar(CheatResponse, "Response1") Response2 = HalBrain.DecodeVar(CheatResponse, "Response2") Response3 = HalBrain.DecodeVar(CheatResponse, "Response3") CheatResponse = Left(CheatResponse, InStr(1, CheatResponse, "", 1) - 1) If Len(CheatResponse) > 4 And Len(GetResponse) < 4 Then Roulette = Int(Rnd * 8) If Roulette = 0 Then GetResponse = GetResponse & " So, " & CheatResponse & VbCrLf If Roulette = 1 Then GetResponse = GetResponse & " Really, " & CheatResponse & VbCrLf If Roulette = 2 Then GetResponse = GetResponse & " Oh , " & CheatResponse & VbCrLf If Roulette = 3 Then GetResponse = GetResponse & " Let me think; " & CheatResponse & " ; what do you think ? " & VbCrLf If Roulette > 3 Then GetResponse = GetResponse & CheatResponse & VbCrLf DebugInfo = DebugInfo & "Hal has responded using the CheatResponse function: " & GetResponse & VbCrLf Else DebugInfo = DebugInfo & "Hal will not respond using the CheatResponse function which would have said: " & CheatResponse & VbCrLf End If 'SAVE: FILE CHEAT RESPONSE TO DEFAULT USER BRAIN 'Learn from the "Cheat Response." If Len(LearnKeyword) > 4 And LearningLevel > 1 And BlockSave = False Then If LearningLevel > 1 Then HalBrain.AppendFile WorkingDir & Trim(UserName) & "user.brn", """" & LearnKeyword & ""","""","""",""" & Response1 & """,""" & Response2 & """,""" & Response3 & """,1,#FALSE#,#FALSE#,""""" End If End If 'RESPOND: GENERATE NEW THOUGHTS FROM SUBJECT/PREDICATE ASSEMBLY 'Hal can assemble a fresh remark from separate subjects and predicates databased from earlier conversations. 'Using this routine, Hal can make observations quite different from anything the user has previously said! 'Because both subjects and predicates are databased as both associative-retrievable and random-retrievable, 'and Hal might use any combination for either a question or answer, Hal can multiply a moderate number of 'remarks from a user into a very large number of new and surprising expressions! GetResponse = Trim(GetResponse) If Len(GetResponse) < 4 And Rnd * 100 < 50 Then PartOne = HalBrain.ChooseSentenceFromFile(WorkingDir & "random_subject.brn") HalUserBrain = HalBrain.QABrain(UserSentence, WorkingDir & "assoc_subject.brn", UserBrainRel) If UserBrainRel > 0 Then MatchSubject = True If UserBrainRel > 0 Then PartOne = HalUserBrain PartTwo = HalBrain.ChooseSentenceFromFile(WorkingDir & "random_predicate.brn") GetResponse = Trim(GetResponse) HalUserBrain = HalBrain.QABrain(UserSentence, WorkingDir & "assoc_predicate.brn", UserBrainRel) If UserBrainRel > 0 Then MatchPredicate = True If UserBrainRel > 0 Then PartTwo = HalUserBrain If MatchSubject = True Or MatchPredicate = True Then PartOne = Trim(PartOne) PartTwo = Trim(PartTwo) PartThree = HalBrain.ChooseSentenceFromFile(WorkingDir & "random_adjective.brn") Roulette = Int(Rnd * 103) If PartOne = PartTwo Or Roulette > 50 Then PartTwo = HalBrain.ChooseSentenceFromFile(WorkingDir & "random_adjective.brn") End If PartOne = Replace("" & PartOne & "", "vbCrLf", " ", 1, -1, vbTextCompare) PartTwo = Replace("" & PartTwo & "", "vbCrLf", " ", 1, -1, vbTextCompare) PartThree = Replace("" & PartThree & "", "vbCrLf", " ", 1, -1, vbTextCompare) PartOne = Replace("" & PartOne & "", "^p", " ", 1, -1, vbTextCompare) PartTwo = Replace("" & PartTwo & "", "^p", " ", 1, -1, vbTextCompare) PartThree = Replace("" & PartThree & "", "^p", " ", 1, -1, vbTextCompare) PartOne = HalBrain.AlphaNumericalOnly(PartOne) PartTwo = HalBrain.AlphaNumericalOnly(PartTwo) PartThree = HalBrain.AlphaNumericalOnly(PartThree) PartOne = LCase(PartOne) PartTwo = LCase(PartTwo) PartThree = LCase(PartThree) SPAssembly = HalBrain.ChooseSentenceFromFile(WorkingDir & "assembly.brn") SPAssembly = Replace(SPAssembly, "", PartOne, 1, -1, vbTextCompare) SPAssembly = Replace(SPAssembly, "", PartTwo, 1, -1, vbTextCompare) SPAssembly = Replace(SPAssembly, "", PartThree, 1, -1, vbTextCompare) GetResponse = GetResponse & SPAssembly & VbCrLf DebugInfo = DebugInfo & "Hal has responded using subject/predicate assembly. " & VbCrLf End If Else DebugInfo = DebugInfo & "Hal will not respond using subject/predicate assembly. " & VbCrLf End If 'RESPOND: USER MENTIONING ORGANIZATIONAL CHALLENGES 'Everybody spouts TLA's, or 'Three Letter Acronyms,' in today's business world. Hal can self-generate 'several MILLION different phrases in response to the user mentioning a corporation or a firm. If HalBrain.TopicSearch(UserSentence, WorkingDir & "bizwords.brn") = "True" And HalBrain.TopicSearch(PrevUserSent, WorkingDir & "bizmore.brn") <> "True" Then TLA = HalBrain.SentenceGenerator(WorkingDir & "random_TLA.brn") Roulette = Int(Rnd * 10) DebugInfo = DebugInfo & "Hal has detected that the user is talking about business. " If Roulette < 5 Then GetResponse = HalBrain.ChooseSentenceFromFile(WorkingDir & "random_tla2.brn") GetResponse = Replace(GetResponse, "", TLA, 1, -1, vbTextCompare) DebugInfo = DebugInfo & "Hal has responded with a random TLA: " & GetResponse & VbCrLf Else DebugInfo = DebugInfo & "Hal has decided not to respond with a TLA." & VbCrLf End If End If 'RESPOND: USER EXPRESSES AN INTENTION 'This routine detects common expressions of motive from the user, 'and allows Hal to react to the statement, or offer encouragement. If HalBrain.TopicSearch(UserSentence, WorkingDir & "intending.brn") = "True" Then IntentSentence = UserSentence 'We don't want pronouns to confuse HalBrain 'or get mixed up in processing, so we encode them 'to make the pronouns go through processing unchanged: IntentSentnece = HalBrain.EncodePronouns(IntentSentence) IntentPhrase = HalBrain.KeywordBrain(IntentSentence, WorkingDir & "intent_detector.brn", False) If Len(IntentPhrase) > 1 And Len(IntentPhrase) < 60 Then 'Now that we've extracted the user's intent phrase, we decode the pronouns and put them back as we found them: IntentPhrase = HalBrain.DecodePronouns(IntentPhrase) If Rnd * 100 < 50 Then IntroExclaim = " " & HalBrain.ChooseSentenceFromFile(WorkingDir & "IntroExclaim1.brn") & " " If Rnd * 100 < 50 Then Encourager = " " & HalBrain.ChooseSentenceFromFile(WorkingDir & "Encourager1.brn") & " " If Rnd * 100 < 50 Then SuffixComment = " " & HalBrain.ChooseSentenceFromFile(WorkingDir & "SuffixComment1.brn") & " " Spinner = Int(Rnd * 16) If Spinner = 0 Then GetResponse = " " & IntroExclaim & Encourager & IntentPhrase & SuffixComment & " " & VbCrLf If Spinner = 1 Then GetResponse = " " & " " & IntroExclaim & Encourager & IntentPhrase & SuffixComment & " " & VbCrLf If Spinner = 2 Then GetResponse = " " & IntroExclaim & " " & Encourager & IntentPhrase & SuffixComment & " " & VbCrLf If Spinner = 3 Then GetResponse = " " & IntroExclaim & Encourager & IntentPhrase & " " & SuffixComment & " " & VbCrLf If Spinner = 4 Then GetResponse = " " & IntroExclaim & Encourager & IntentPhrase & SuffixComment & " " & " " & VbCrLf If Spinner = 5 Then GetResponse = " " & IntroExclaim & Encourager & IntentPhrase & SuffixComment & " " & VbCrLf If Spinner = 6 Then GetResponse = " How can I encourage you to " & IntentPhrase & " ? " & VbCrLf If Spinner = 7 Then GetResponse = " How can I help you " & IntentPhrase & " ? " & VbCrLf If Spinner = 8 Then GetResponse = " How can I encourage you to " & IntentPhrase & " ? " & VbCrLf If Spinner = 9 Then GetResponse = " How can I help you " & IntentPhrase & " ? " & VbCrLf If Spinner = 10 Then GetResponse = " " & IntroExclaim & Encourager & IntentPhrase & SuffixComment & " " & VbCrLf If Spinner = 11 Then GetResponse = " " & " " & IntroExclaim & Encourager & IntentPhrase & SuffixComment & " " & VbCrLf If Spinner = 12 Then GetResponse = " " & IntroExclaim & " " & Encourager & IntentPhrase & SuffixComment & " " & VbCrLf If Spinner = 13 Then GetResponse = " " & IntroExclaim & Encourager & IntentPhrase & " " & SuffixComment & " " & VbCrLf If Spinner = 14 Then GetResponse = " " & IntroExclaim & Encourager & IntentPhrase & SuffixComment & " " & " " & VbCrLf If Spinner = 15 Then GetResponse = " " & IntroExclaim & Encourager & IntentPhrase & SuffixComment & " " & VbCrLf DebugInfo = DebugInfo & "The user has expressed a motive and Hal has responded: " & GetResponse & VbCrLf End If End If 'RESPOND: USER EXPRESSES AN EXPLANATION 'This routine detects common expressions of reasons from the user, 'and allows Hal to react to the explanation. If HalBrain.TopicSearch(UserSentence, WorkingDir & "Explaining.brn") = "True" Then ExplainSentence = UserSentence 'We don't want pronouns to confuse HalBrain 'or get mixed up in processing, so we encode them 'to make the pronouns go through processing unchanged: ExplainSentence = HalBrain.EncodePronouns(ExplainSentence) ExplainPhrase = HalBrain.KeywordBrain(ExplainSentence, WorkingDir & "reason_detector.brn", False) If Len(ExplainPhrase) > 1 And Len(ExplainPhrase) < 60 Then 'Now that we've extracted the user's intent phrase, we decode the pronouns and put them back as we found them: ExplainPhrase = HalBrain.DecodePronouns(ExplainPhrase) If Rnd * 100 < 75 Then IntroExclaim = HalBrain.ChooseSentenceFromFile(WorkingDir & "IntroExlaim4.brn") Enlightener = HalBrain.ChooseSentenceFromFile(WorkingDir & "Enlightener.brn") If Rnd * 100 < 75 Then SuffixComment = HalBrain.ChooseSentenceFromFile(WorkingDir & "SuffixComment4.brn") Spinner = Int(Rnd * 6) If Spinner = 0 Then GetResponse = " " & IntroExclaim & Enlightener & ExplainPhrase & SuffixComment & " " If Spinner = 1 Then GetResponse = " " & " " & IntroExclaim & Enlightener & ExplainPhrase & SuffixComment & " " If Spinner = 2 Then GetResponse = " " & IntroExclaim & " " & Enlightener & ExplainPhrase & SuffixComment & " " If Spinner = 3 Then GetResponse = " " & IntroExclaim & Enlightener & ExplainPhrase & " " & SuffixComment & " " If Spinner = 4 Then GetResponse = " " & IntroExclaim & Enlightener & ExplainPhrase & SuffixComment & " " & " " If Spinner = 5 Then GetResponse = " " & IntroExclaim & Enlightener & ExplainPhrase & SuffixComment & " " DebugInfo = DebugInfo & "The user has expressed a explanation and Hal has responded: " & GetResponse & VbCrLf End If End If 'PROCESS: USER SENTENCE FOR KEYWORD BRAINS 'This routine allows Hal to learn keyword files with correct pronoun reversals and some of 'the user's punctuation intact, especially question marks and exclamation points. We learn 'from the user's sentence if it contains linking verbs. In this first section Hal 'preprocesses the user's sentence. Later we save into one of several user keyword brain files. 'Before we go further, we save a copy 'of the pronoun-reversed user's sentence. SaveUserSentence = UserSentence UserSentence = HalBrain.RemovePronouns(UserSentence) 'Now Hal makes keywords and responses with no confusion over pronouns: learninfo = HalBrain.Learn(UserSentence) LearnKeyword = HalBrain.DecodeVar(learninfo, "LearnKeyword") LearnKeyword2 = HalBrain.DecodeVar(learninfo, "LearnKeyword2") Response1 = HalBrain.DecodeVar(learninfo, "Response1") Response2 = HalBrain.DecodeVar(learninfo, "Response2") Response3 = HalBrain.DecodeVar(learninfo, "Response3") LearnKeyword = Trim(LearnKeyword) 'Remember, all thinking is done in all caps. To the extent possible, we recover some punctuation 'at this point from the user's original sentence, and add some spaces before and after the 'sentence which are useful when Hal retrieves more than one keyword response at a time from any 'of the databases. We start by restoring the pronouns into the user's sentence again: UserSentence = SaveUserSentence 'Now we establish a special sentence on which we can restore ordinary capitalization: SpecialSent = UserSentence SpecialSent = HalBrain.FixCaps(SpecialSent) 'Now we add in our spaces and restore ending punctuation to match the user's original sentence: If InStr(OriginalSentence, ".") > 0 Then SpecialSent = Replace(" " & SpecialSent & " ", ".", ".", 1, -1, vbTextCompare) If InStr(OriginalSentence, "?") > 0 Then SpecialSent = Replace(" " & SpecialSent & " ", ".", "?", 1, -1, vbTextCompare) If InStr(OriginalSentence, "!") > 0 Then SpecialSent = Replace(" " & SpecialSent & " ", ".", "!", 1, -1, vbTextCompare) 'If there were no pronoun reversals required in the sentence, 'we can recover directly from the original sentence: If InStr(UserSentence, " ME") = 0 And InStr(UserSentence, "YOU") = 0 And InStr(UserSentence, "MY ") = 0 And InStr(UserSentence, "YOUR ") = 0 And InStr(UserSentence, "I ") = 0 And InStr(UserSentence, "MINE") = 0 And InStr(UserSentence, "YOURS") = 0 And InStr(UserSentence, "MYSELF") = 0 And InStr(UserSentence, "YOURSELF") = 0 Then SpecialSent = OriginalSentence 'SAVE FILE USER DEFAULT KEYWORD BRAIN 'Here we save any information learned in the default user keyword brain file for compatibility. If HalBrain.CheckLinkingVerb(UserSentence) = True Then LearnKeyword = Replace("" & LearnKeyword & "", " EMAIL ADDRESS ", " EMAIL ", 1, -1, vbTextCompare) If Len(LearnKeyword) > 4 And Len(LearnKeyword2) > 4 And BlockSave = False Then If LearningLevel > 1 Then HalBrain.AppendFile WorkingDir & Trim(UserName) & "user.brn", """" & LearnKeyword & ""","""","""",""" & SpecialSent & """,""" & Response2 & """,""" & Response3 & """,1,#FALSE#,#FALSE#,""""" & VbCrLf & """" & LearnKeyword2 & ""","""","""",""" & SpecialSent & """,""" & Response2 & """,""" & Response3 & """,1,#FALSE#,#FALSE#,""""" DebugInfo = DebugInfo & "Hal has learned new information and has placed it in the file " & Trim(UserName) & "user.brn" & VbCrLf End If 'SAVE FILE USER BACKUP ADDRESS BRAIN 'Here we save any information learned 'about numbers and addresses. If InStr(OriginalSentence, "ADDRESS") > 0 Then BackupData = True If InStr(OriginalSentence, "MAIL") > 0 Then BackupData = True If InStr(OriginalSentence, "PHONE") > 0 Then BackupData = True If InStr(OriginalSentence, "NUMBER") > 0 Then BackupData = True If InStr(OriginalSentence, "address") > 0 Then BackupData = True If InStr(OriginalSentence, "mail") > 0 Then BackupData = True If InStr(OriginalSentence, "phone") > 0 Then BackupData = True If InStr(OriginalSentence, "number") > 0 Then BackupData = True If InStr(OriginalSentence, "what is") > 0 Then BackupData = False If InStr(OriginalSentence, "where is") > 0 Then BackupData = False If BackupData = True Then If LearningLevel > 1 Then HalBrain.AppendFile WorkingDir & Trim(UserName) & "user_backup.brn", """" & Left(OriginalSentence, 15) & ""","""","""",""" & SpecialSent & """,""" & Response2 & """,""" & Response3 & """,1,#FALSE#,#FALSE#,""""" DebugInfo = DebugInfo & "Hal has learned new information and has placed it in the file " & Trim(UserName) & "user_backup.brn" & VbCrLf End If 'SAVE FILE USER KEYWORD BRAIN 0 1 2 'Hal now also selects and writes to one of three keyword files at random. The use of 'these three user keyword files provides more variety of responses when it is not 'necessary to search for specific factual data. In these files, we only accept words 'and phrases with a length greater than 9 in order to reduce repetitive-triggering on 'short common words. If Len(LearnKeyword) > 9 And Len(LearnKeyword2) > 9 And BlockSave = False Then LearnKeyword_A = Left(LearnKeyword, 20) LearnKeyword_B = Left(LearnKeyword2, 20) Roulette = Int(Rnd * 3) If Roulette = 0 And LearningLevel > 1 Then HalBrain.AppendFile WorkingDir & Trim(UserName) & "user0.brn", """" & LearnKeyword_A & ""","""","""",""" & SpecialSent & """,""" & Response2 & """,""" & Response3 & """,1,#FALSE#,#FALSE#,""""" & VbCrLf & """" & LearnKeyword_B & ""","""","""",""" & SpecialSent & """,""" & Response2 & """,""" & Response3 & """,1,#FALSE#,#FALSE#,""""" If Roulette = 1 And LearningLevel > 1 Then HalBrain.AppendFile WorkingDir & Trim(UserName) & "user1.brn", """" & LearnKeyword_A & ""","""","""",""" & SpecialSent & """,""" & Response2 & """,""" & Response3 & """,1,#FALSE#,#FALSE#,""""" & VbCrLf & """" & LearnKeyword_B & ""","""","""",""" & SpecialSent & """,""" & Response2 & """,""" & Response3 & """,1,#FALSE#,#FALSE#,""""" If Roulette = 2 And LearningLevel > 1 Then HalBrain.AppendFile WorkingDir & Trim(UserName) & "user2.brn", """" & LearnKeyword_A & ""","""","""",""" & SpecialSent & """,""" & Response2 & """,""" & Response3 & """,1,#FALSE#,#FALSE#,""""" & VbCrLf & """" & LearnKeyword_B & ""","""","""",""" & SpecialSent & """,""" & Response2 & """,""" & Response3 & """,1,#FALSE#,#FALSE#,""""" DebugInfo = DebugInfo & "Hal has learned new information and has placed it in the file " & Trim(UserName) & "user" & Roulette & ".brn" & VbCrLf End If End If 'RESPOND: PHRASE MAKER COMMENT AND QUESTION GENERATOR 'If no response is found yet, try an auxiliary keyword file that generates questions 'from phrases from the user's current sentence. GetResponse = HalBrain.HalFormat(GetResponse) If Len(GetResponse) < 4 Then KeyBrain = HalBrain.KeywordBrain(UserSentence, WorkingDir & "phrase_detector.brn", False) If Len(KeyBrain) > 1 And Len(KeyBrain) < 60 Then GetResponse = GetResponse & Replace(HalBrain.ChooseSentenceFromFile(WorkingDir & "phrasemaker.Brn"), "", KeyBrain, 1, -1, vbTextCompare) DebugInfo = DebugInfo & "The phrase_detector.brn keyword brain has come up with a response: " & GetResponse & VbCrLf End If End If 'SAVE: NOUN WORDS 'Hal attempts to save noun words for future use. GetResponse = HalBrain.HalFormat(GetResponse) Nounwords = HalBrain.KeywordBrain(UserSentence, WorkingDir & "Nouns_detector.brn", False) Nounwords = HalBrain.HalFormat(Nounwords) Disqualify = False If HalBrain.TopicSearch(Nounwords, WorkingDir & "disqualify1.brn") = "True" Then Disqualify = True If HalBrain.TopicSearch(UserSentence, WorkingDir & "disqualify2.brn") = "True" Then Disqualify = True Nounwords = Trim(Nounwords) Nounwords = Trim(HalBrain.ProcessSubstitutions(Nounwords, WorkingDir & "extract1.brn")) If HalBrain.CountInstances(" ", NounWords) > 0 Then Disqualify = True If Len(Nounwords) > 4 And Len(Nounwords) < 12 And Disqualify = False And BlockSave = False And LearningLevel > 1 Then HalBrain.AppendFile WorkingDir & "random_subject.brn", " " & Nounwords & " " HalBrain.AppendFile WorkingDir & "assoc_subject.brn", "@" & Nounwords & VbCrLf & " " & UCase(Nounwords) DebugInfo = DebugInfo & "Hal has learned a new noun and stored it in his noun files: " & Nounwords & VbCrLf End If 'SAVE: ADJECTIVE WORDS AND PHRASES 'Hal attempts to save adjective words and phrases for future use. GetResponse = HalBrain.HalFormat(GetResponse) AdjectiveWords = HalBrain.KeywordBrain(UserSentence, WorkingDir & "Adjectives_detector.brn", False) AdjectiveWords = HalBrain.HalFormat(AdjectiveWords) Disqualify = False If HalBrain.TopicSearch(UserSentence, WorkingDir & "disqualify4.brn") = "True" Then Disqualify = True If HalBrain.TopicSearch(AdjectiveWords, WorkingDir & "disqualify3.brn") = "True" Then Disqualify = True AdjectiveWords = HalBrain.HalFormat(AdjectiveWords) AdjectiveWords = UCase(AdjectiveWords) AdjectiveWords = HalBrain.ProcessSubstitutions(AdjectiveWords, WorkingDir & "extract3.brn") AdjectiveWords = HalBrain.HalFormat(AdjectiveWords) If HalBrain.CountInstances(" ", AdjectiveWords) > 2 Then Disqualify = True If Len(AdjectiveWords) > 3 And Len(AdjectiveWords) < 19 And Disqualify = False Then If LearningLevel > 1 Then HalBrain.AppendFile WorkingDir & "random_adjective.brn", "" & AdjectiveWords & "" If LearningLevel > 1 Then HalBrain.AppendFile WorkingDir & "assoc_adjective.brn", "@" & AdjectiveWords & VbCrLf & AdjectiveWords DebugInfo = DebugInfo & "Hal has learned a new adjective and stored it in his adjective files: " & AdjectiveWords & VbCrLf End If 'SAVE: WORDS THAT ARE "MY" TO HAL 'Hal attempts to save words about himself for future use. GetResponse = HalBrain.HalFormat(GetResponse) MyWords = HalBrain.KeywordBrain(UserSentence, WorkingDir & "My_detector.brn", False) MyWords = HalBrain.HalFormat(MyWords) Disqualify = False If HalBrain.TopicSearch(MyWords, WorkingDir & "disqualify3.brn") = "True" Then Disqualify = True MyWords = HalBrain.HalFormat(MyWords) MyWords = UCase(MyWords) MyWords = HalBrain.HalFormat(MyWords) MyWordsKey = UCase(Replace("" & MyWords & "", "MY", "", 1, -1, vbTextCompare) ) MyWords = Trim(HalBrain.AlphaNumericalOnly(MyWords)) MyWordsKey = Trim(HalBrain.AlphaNumericalOnly(MyWordsKey)) If HalBrain.CountInstances(" ", MyWords) > 0 Then Disqualify = True If Len(MyWords) > 3 And Len(MyWords) < 19 And Disqualify = False And LearningLevel > 1 Then HalBrain.AppendFile WorkingDir & "random_MyWords.brn", "" & MyWords & "" HalBrain.AppendFile WorkingDir & "assoc_MyWords.brn", "@" & MyWords & VbCrLf & " " & MyWordsKey DebugInfo = DebugInfo & "Hal has learned a new 'my' word and stored it in his mywords files: " & MyWords & VbCrLf End If 'SAVE: WORDS THAT ARE "YOUR" TO THE USER 'Hal attempts to save words about the user for future use. GetResponse = HalBrain.HalFormat(GetResponse) YourWords = HalBrain.KeywordBrain(UserSentence, WorkingDir & "Your_detector.brn", False) YourWords = HalBrain.HalFormat(YourWords) Disqualify = False If HalBrain.TopicSearch(MyWords, WorkingDir & "disqualify3.brn") = "True" Then Disqualify = True YourWords = HalBrain.HalFormat(YourWords) YourWords = Trim(HalBrain.ProcessSubstitutions(YourWords, WorkingDir & "extract5.brn")) If HalBrain.CountInstances(" ", YourWords) > 0 Then Disqualify = True If Len(YourWords) > 3 And Len(YourWords) < 19 And Disqualify = False And LearningLevel > 1 Then HalBrain.AppendFile WorkingDir & "random_YourWords.brn", "" & YourWords & "" HalBrain.AppendFile WorkingDir & "assoc_YourWords.brn", "@" & YourWords & VbCrLf & " " & UCase(YourWords) DebugInfo = DebugInfo & "Hal has learned a new 'your' word and stored it in his yourwords files: " & YourWords & VbCrLf End If 'RESPOND: HAL'S POSITIVE TOPIC ASSOCIATIONS If Len(GetResponse) < 4 Then NiceFeeling = HalBrain.ChooseSentenceFromFile(WorkingDir & "random_14pos_action_phrases.brn") NiceThings = HalBrain.ChooseSentenceFromFile(WorkingDir & "random_15pos_object_phrases.brn") If Rnd * 100 > 65 Then GetResponse = " " & NiceFeeling & " " & NiceThings & " " DebugInfo = DebugInfo & "Hal has responded with a positive topic association: " & GetResponse & VbCrLf End If End If 'RESPOND: YES OR NO RESPONSES 'Respond to simple yes and no statements by the user. GetResponse = HalBrain.HalFormat(GetResponse) If Len(GetResponse) < 4 And Len(UserSentence) < 15 Then CheckYesNo = True If CheckYesNo = True Then UserText = Trim(HalBrain.ExtractKeywords(UserSentence)) If Len(UserText) < 15 Then YesNoDetect = HalBrain.TopicSearch(UserText, WorkingDir & "YesNoDetect.brn") If YesNoDetect = "Yes" Then YesRes = True Else YesRes = False If YesNoDetect = "No" Then NoRes = True Else NoRes = False If YesRes = True And NoRes = False Then GetResponse = GetResponse & HalBrain.ChooseSentenceFromFile(WorkingDir & "YesRes.brn") ElseIf NoRes = True And YesRes = False Then GetResponse = GetResponse & HalBrain.ChooseSentenceFromFile(WorkingDir & "NoRes.brn") ElseIf NoRes = True And YesRes = True Then GetResponse = GetResponse & "Yes or No? Which is it?" End If If YesRes = True Or NoRes = True Then DebugInfo = DebugInfo & "Hal has detected a Yes or No response and has responded to it: " & GetResponse & VbCrLf End If End If 'RESPOND: ZABAWARE KEYWORD BRAIN PRIORITIES 2 3 4 'If no Response is found yet, try a lower priority keyword match 'in the Enhanced Main brn file. Spinner = Int(Rnd * 400) GetResponse = HalBrain.HalFormat(GetResponse) If Len(GetResponse) < 4 And Spinner < 200 Then KeyBrain = HalBrain.KeywordBrain(UserSentence, WorkingDir & "Enhanced_Main.brn", False) If Len(KeyBrain) > 3 Then GetResponse = KeyBrain & VbCrLf DebugInfo = DebugInfo & "Hal has responded using a lower priority keyword match in enhanced_main.brn: " & KeyBrain & VbCrLf End If End If 'RESPOND: Use the highest relevance response from the database functions GetResponse = HalBrain.HalFormat(GetResponse) DebugInfo = DebugInfo & "The highest relevance responsee has a rating of " & HighestRel & " and is """ & HighestRelResponse & """ " If ((Len(GetResponse) < 4 And Rnd * 100 < 60) And (HighestRel > 5 And HighestRelResponse <> "")) Or ((Rnd * 100 > 90) And (HighestRel > 12 And HighestRelResponse <> "") And HalGreeting = "") Then DebugInfo = DebugInfo & "Hal has decided to use this sentence instead of the response currently in memory, which was: " & GetResponse & VbCrLf GetResponse = HighestRelResponse Else DebugInfo = DebugInfo & "Hal will not use this sentence in place of the currently response in memory. " & VbCrLf End If 'RESPOND: User asks a general opinion question. If HalBrain.TopicSearch(UserSentence, WorkingDir & "opiniondetect.brn") = "True" Then GenOpinion = True 'Note that the following string matches must occur at the sentence beginning only: Roulette = Int(Rnd * 100) If Roulette > 50 Then If InStr(Trim(UCase(UserSentence)), "WHY ") = 1 Then GenOpinion = True If InStr(Trim(UCase(UserSentence)), "WHAT ") = 1 Then GenOpinion = True If InStr(Trim(UCase(UserSentence)), "WHEN ") = 1 Then GenOpinion = True If InStr(Trim(UCase(UserSentence)), "HOW ") = 1 Then GenOpinion = True If InStr(Trim(UCase(UserSentence)), "WHO ") = 1 Then GenOpinion = True If InStr(Trim(UCase(UserSentence)), "WHERE ") = 1 Then GenOpinion = True End If If GenOpinion = True And OrigBrain = "" Then If Rnd * 100 > 25 Then RepeatQuest = UserSentence & " ? " If Rnd * 100 > 50 Then PreAmble = HalBrain.ChooseSentenceFromFile(WorkingDir & "preamble.brn") Recommend = HalBrain.ChooseSentenceFromFile(WorkingDir & "recommend.brn") GetResponse = RepeatQuest & " " & PreAmble & " " & Recommend & GetResponse DebugInfo = DebugInfo & "Hal has responded to a general opinion question." & VbCrLf End If 'RESPOND: CALL MAKETALK FUNCTION 'This function assembles sentences from components. GetResponse = HalBrain.HalFormat(GetResponse) If Len(GetResponse) < 4 And Rnd * 300 < 100 Then GetResponse = HalBrain.SentenceGenerator(WorkingDir & "sentgen.brn") DebugInfo = DebugInfo & "Hal has responded using the sentgen.brn file: " & GetResponse & VbCrLf End If 'RESPOND: USE RANDOM QUESTION COLLECTED FROM USER 'If Hal has not found a response yet, he will randomly select a 'question once posed by the user in order to find something to say. 'If the user answers the question, then Hal will know that answer 'in the future. For variety, we make triggering of this response 'dependent on a random number. Spinner = Int(Rnd * 700) GetResponse = HalBrain.HalFormat(GetResponse) If Len(GetResponse) < 4 And Spinner < 350 Then GetResponse = HalBrain.ChooseSentenceFromFile(WorkingDir & Trim(UserName) & "user_question.brn") DebugInfo = DebugInfo & "Hal has responded using user_question.brn file: " & GetResponse & VbCrLf End If 'RESPOND: USER EXPRESSES AN EITHER-OR, OR MULTIPLE CHOICE If InStr(UserSentence, " OR ") > 0 Then MustChoose = True If InStr(UserSentence, " EITHER ") > 0 Then MustChoose = True If InStr(UserSentence, " CHOOSE ") > 0 Then MustChoose = True If InStr(UserSentence, " CHOICE ") > 0 Then MustChoose = True If InStr(UserSentence, " ALTERNATIVE ") > 0 Then MustChoose = True If InStr(UserSentence, " VERSUS ") > 0 Then MustChoose = True If InStr(UserSentence, " VS ") > 0 Then MustChoose = True If Len(UserSentence) < 10 Then MustChoose = False If MustChoose = True And NoChoosing = False Then GetResponse = HalBrain.ChooseSentenceFromFile(WorkingDir & "choice.brn") & " " & GetResponse If Rnd * 100 > 50 Then GetResponse = Replace(GetResponse, "", "", 1, -1, vbTextCompare) GetResponse = Replace(GetResponse, "", "", 1, -1, vbTextCompare) DebugInfo = DebugInfo & "Hal has responded to an either-or question: " & GetResponse & VbCrLf End If 'PROCESS: RECORD TIME 'Record the current time, so Hal knows the time in between sentences. LastResponseTime = Now 'SAVE: FILE HAL/USER SENTENCE ASSOCIATIONS 'If the user seems to be continuing a line of thought 'from something Hal just said, Hal associates words 'from Hal's previous statement with the user's sentence 'and stores the resulting association in a special user sentence file. Responding = False If InStr(PrevSent, "?") > 0 Then Responding = True If InStr(OriginalSentence, "!") > 0 Then Responding = True If HalBrain.TopicSearch(UserSentence, WorkingDir & "Responding.brn") = "True" Then Responding = True If Responding = True Then PrevSent = HalBrain.AlphaNumericalOnly(PrevSent) PrevSent = UCase(PrevSent) AnswerSent = "@" & Trim(SpecialSent) QuestionSent = " " & Trim(HalBrain.ExtractKeywords(PrevSent)) If HalBrain.CountInstances(" ", QuestionSent) > 3 And Len(AnswerSent) > 8 And Len(QuestionSent) > 8 And InStr(1, AnswerSent, " ", vbTextCompare) > 0 And BlockSave = False Then If Learninglevel > 1 Then HalBrain.AppendFile WorkingDir & Trim(UserName) & "convresp.brn", AnswerSent & VbCrLf & QuestionSent End If End If 'SAVE: FILE USER STRINGS 'This routine saves the users response. Later a function will extract 15-character strings 'from the beginning, end, and middle of the user's remark for possible later response. UserSentence = " " & Trim(UserSentence) & " " If Len(UserSentence) > 20 And Len(UserSentence) < 90 Then If Learninglevel > 1 Then HalBrain.AppendFile WorkingDir & Trim(UserName) & "user_strings.brn", " " & Trim(SpecialSent) End If 'SAVE: FILE USER SENTENCE DEFAULT 'Unless the user seems to be asking for data recall, Hal always adds 'to the default brain user sentence file an association of the current 'user sentence With words selected from that same current user sentence. If InStr(UserSentence, "WHAT IS") = 0 And Responding = False Then AnswerSent = "@" & Trim(SpecialSent) QuestionSent = " " & Trim(HalBrain.ExtractKeywords(UserSentence)) If HalBrain.CountInstances(" ", QuestionSent) > 3 And Len(AnswerSent) > 8 And Len(QuestionSent) > 8 And InStr(1, AnswerSent, " ", vbTextCompare) > 0 Then If LearningLevel > 1 Then HalBrain.AppendFile WorkingDir & Trim(UserName) & "usersent.brn", AnswerSent & VbCrLf & QuestionSent End If End If 'SAVE: FILE SHARED USER SENTENCES 'Unless the user seems to be asking for data recall, or talking about 'himself or herself, Hal adds to a shared user sentence file. This allows 'Hal to gain knowledge that he can apply to conversations with multiple users. If Responding = False And InStr(UserSentence, "WHAT IS") = 0 And InStr(UserSentence, " YOU ") = 0 And InStr(UserSentence, " YOU'") = 0 And InStr(UserSentence, " YOUR ") = 0 And InStr(UserSentence, " YOURS ") = 0 And InStr(UserSentence, " YOURSELF ") = 0 And InStr(UserSentence, " WE ") = 0 And InStr(UserSentence, " US ") = 0 And InStr(UserSentence, " OUR ") = 0 And InStr(UserSentence, " I ") = 0 And InStr(UserSentence, " ME ") = 0 And InStr(UserSentence, " MY ") = 0 And InStr(UserSentence, " MINE ") = 0 And InStr(UserSentence, " MYSELF ") = 0 And InStr(UserSentence, " I' ") = 0 Then AnswerSent = "@" & Trim(SpecialSent) QuestionSent = " " & Trim(HalBrain.ExtractKeywords(UserSentence)) If HalBrain.CountInstances(" ", QuestionSent) > 3 And Len(AnswerSent) > 8 And Len(QuestionSent) > 8 And InStr(1, AnswerSent, " ", vbTextCompare) > 0 And BlockSave = False Then If LearningLevel > 1 Then HalBrain.AppendFile WorkingDir & "shared_usersent.brn", AnswerSent & VbCrLf & QuestionSent End If End If 'SAVE: FILE ADDRESS AND NUMBER BACKUP 'Unless the user seems to be asking for data recall, Hal will also put 'sentences that have to Do with addresses and numbers into a special 'user recall file that adds a backup source for factual data. If InStr(UserSentence, "WHAT IS") = 0 And InStr(UserSentence, "ADDRESS") > 0 Or InStr(UserSentence, "NUMBER") > 0 Then AnswerSent = "@" & Trim(SpecialSent) QuestionSent = " " & Trim(HalBrain.ExtractKeywords(UserSentence)) If HalBrain.CountInstances(" ", QuestionSent) > 2 And Len(AnswerSent) > 8 And Len(QuestionSent) > 8 And InStr(1, AnswerSent, " ", vbTextCompare) > 0 Then If LearningLevel > 1 Then HalBrain.AppendFile WorkingDir & Trim(UserName) & "user_recall.brn", AnswerSent & VbCrLf & QuestionSent End If End If 'SAVE TOPIC SENTENCE IN APPROPRIATE FILE IF CURRENTLY IN TOPICFOCUS MODE If TopicFocus > 10 And TopicFocus = FocusFileNum Then AnswerSent = "@" & Trim(SpecialSent) QuestionSent = " " & Trim(HalBrain.ExtractKeywords(UserSentence)) If HalBrain.CountInstances(" ", QuestionSent) > 2 And Len(AnswerSent) > 8 And Len(QuestionSent) > 8 And InStr(1, AnswerSent, " ", vbTextCompare) > 0 And BlockSave = False Then If LearningLevel > 1 Then HalBrain.AppendFile WorkingDir & Trim(UserName) & "topic" & FocusFileNum & ".brn", AnswerSent & VbCrLf & QuestionSent End If End If 'RESPOND: USER DEFAULT USER KEYWORD BRAIN (QUALIFIED) 'If the user seems to be asking for recall of specific information Hal 'needs to check the file where addresses and numbers might be stored. If 'our keyword requirements are met, we direct the user's inquiry to the 'default user keyword file that is used with other brain plug-ins to 'maintain compatibility with previous files the user may have created. If InStr(UserSentence, "CAPITAL") = 0 And InStr(UserSentence, "WHAT IS") > 0 And InStr(UserSentence, "WHAT IS NEW ") = 0 Or InStr(UserSentence, "MAIL") > 0 Or InStr(UserSentence, "ADDRESS") > 0 Or InStr(UserSentence, "NUMBER") > 0 Then KeyBrain = HalBrain.KeywordBrain(UserSentence, WorkingDir & Trim(UserName) & "user.brn", False) If Len(KeyBrain) > 3 Then GetResponse = KeyBrain & VbCrLf DebugInfo = DebugInfo & "Hal has responded using the USER DEFAULT USER KEYWORD BRAIN (QUALIFIED): " & KeyBrain & VbCrLf End If End If 'RESPOND: USER BACKUP BRAIN (QUALIFIED) 'If the user seems to be asking for recall of specific information Hal 'needs to check the file where addresses and numbers might be stored. 'If our keyword requirements are met, we direct the user's inquiry to 'the backup user keyword file. If InStr(UserSentence, "WHAT") > 0 Then AskData = True If InStr(UserSentence, "WHERE") > 0 Then AskData = True If InStr(UserSentence, "EMAIL") > 0 Then AskData = True If InStr(UserSentence, "SEND") > 0 Then AskData = True If InStr(UserSentence, "MAIL") > 0 Then WantsData = True If InStr(UserSentence, "ADDRESS") > 0 Then WantsData = True If InStr(UserSentence, "NUMBER") > 0 Then WantsData = True If AskData = True And WantsData = True Then KeyBrain = HalBrain.KeywordBrain(UserSentence, WorkingDir & Trim(UserName) & "user_backup.brn", False) If Len(KeyBrain) > 3 Then GetResponse = KeyBrain & VbCrLf KeyBrain = HalBrain.KeywordBrain(UserSentence, WorkingDir & Trim(UserName) & "user.brn", False) If Len(KeyBrain) > 3 Then GetResponse = GetResponse & " Right ? " & KeyBrain & " ! " & VbCrLf DebugInfo = DebugInfo & "Hal has responded using the USER BACKUP BRAIN (QUALIFIED): " & GetResponse & VbCrLf End If 'SAVE: FILE QUESTIONS IN RANDOM QUESTION RETRIEVAL FILE 'Hal saves the user's questions (with pronouns reversed) 'so that he can pose questions back to the user later for 3 purposes: '1. If the user answers a question later, Hal will learn the answer. '2. It adds variety to future conversations for the user. '3. It gives Hal another possible response when "stuck" for an answer. QuestionLength = HalBrain.HalFormat(SpecialSent) If InStr(1, SpecialSent, "?", vbTextCompare) > 0 Then GoodQuest = True If InStr(1, SpecialSent, "Who ", vbTextCompare) > 0 Then GoodQuest = True If InStr(1, SpecialSent, "What ", vbTextCompare) > 0 Then GoodQuest = True If InStr(1, SpecialSent, "When ", vbTextCompare) > 0 Then GoodQuest = True If InStr(1, SpecialSent, "Where ", vbTextCompare) > 0 Then GoodQuest = True If InStr(1, SpecialSent, "Why ", vbTextCompare) > 0 Then GoodQuest = True If InStr(1, SpecialSent, "How ", vbTextCompare) > 0 Then GoodQuest = True If InStr(1, SpecialSent, ".", vbTextCompare) > 0 Then GoodQuest = False If InStr(1, SpecialSent, "!", vbTextCompare) > 0 Then GoodQuest = False If InStr(1, SpecialSent, " am I ", vbTextCompare) > 0 Then GoodQuest = False If Len(QuestionLength) < 15 Then GoodQuest = False If GoodQuest = True And BlockSave = False And LearningLevel > 1 Then HalBrain.AppendFile WorkingDir & Trim(UserName) & "user_question.brn", SpecialSent & VbCrLf & SpecialSent 'POST PROCESS: LIMIT FILE SIZE 'We want to make sure the sentence files 'don't get too big so we limit them. HalBrain.LimitSize WorkingDir & "shared_usersent.brn", 2000000 HalBrain.LimitSize WorkingDir & Trim(UserName) & "convresp.brn", 2000000 HalBrain.LimitSize WorkingDir & Trim(UserName) & "user0.brn", 2000000 HalBrain.LimitSize WorkingDir & Trim(UserName) & "user1.brn", 2000000 HalBrain.LimitSize WorkingDir & Trim(UserName) & "user2.brn", 2000000 HalBrain.LimitSize WorkingDir & Trim(UserName) & "usersent.brn", 2000000 HalBrain.LimitSize WorkingDir & Trim(UserName) & "user_question.brn", 2000000 HalBrain.LimitSize WorkingDir & Trim(UserName) & "user_strings.brn", 2000000 'RESPOND: HAL NOTICES HE IS REPEATING HIMSELF 'Hal may make a comment or alter his remark 'if he detects himself being repetitious. If HalBrain.CheckRepetition(GetResponse, PrevSent) = True Then RepeatResponse = HalBrain.ChooseSentenceFromFile(WorkingDir & "halrepeat.brn") GetResponse = Replace(RepeatResponse, "", GetResponse, 1, -1, vbTextCompare) DebugInfo = DebugInfo & "Hal has noticed he is repeating himself and has made a comment about it: " & GetResponse & VbCrLf End If 'RESPOND: MAKE COMMENTS ABOUT SHORT PHRASES GetResponse = GetResponse & ShortPhrase 'PROCESS: REVERSE CERTAIN CONTRACTIONS AND OTHER SUBSTITUTIONS 'Standardizing on contractions can make Hal sound conversational. 'However, certain sentence constructions don't work well 'if expressed as contractions. For example: '"I don't know where it is" becomes "I don't know where it's." 'For another example, "That's how he is" becomes "That's how he's." 'To solve these types of cases 'we attempt to modify certain contractions, words, and phrases 'at the end of this function, now that Hal's thinking is done. GetResponse = HalBrain.HalFormat(GetResponse) GetResponse = HalBrain.ProcessSubstitutions(GetResponse, WorkingDir & "Corrections.brn") 'RESPOND: CHANGE TOPIC 'If a different procedure has requested that the topic be changed 'Hal will do so now NewTopic = HalBrain.ChooseSentenceFromFile(WorkingDir & "topic.brn") GetResponse = Replace(GetResponse, "", NewTopic, 1, -1, vbTextCompare) GetResponse = Replace(GetResponse, "", NewTopic, 1, -1, vbTextCompare) GetResponse = Replace(GetResponse, "", NewTopic, 1, -1, vbTextCompare) GetResponse = Trim(GetResponse) If GetResponse = "" Then GetResponse = NewTopic '---------------------------------------------- 'SAVE: AUTO-TOPIC: Store sentences databased automatically by topic names: 'Hal attempts to save sentences in topic-name-coded databases: '(This is much later in the script 'than the "respond" portion of this routine 'so that Hal can take advantage of the SpecialSent variant 'which has sentence-case capitalization plus correct punctuation) If Len(AutoTopic)>4 And Len(AutoRFileName)>8 And Len(AutoAFileName)>8 And BlockSave = False And LearningLevel > 1 Then 'We create topic-name-coded files containing '"random" responses within topic: HalBrain.AppendFile WorkingDir & AutoRFileName, Trim(SpecialSent) 'We also create topic-name-coded files containing '"associations" between responses and preceding remarks '(these files can be evaluated by the "Q and A" routine): HalBrain.AppendFile WorkingDir & AutoAFileName, "@" & Trim(SpecialSent) & VbCrLf & " " & UCase(Trim(PrevSent)) End If '---------------------------------------------- 'POST PROCESS: SAVE HAL'S RESPONSE PrevSent = GetResponse 'POST PROCESS: PRESERVE ALL VARIABLES 'Remember all the variables through encoding them into one function string using 'the DLL, since for some reason ByRef assignments don't work when a Visual Basic 'executable is calling a function in a VBScript program. PrevUserSent = UserSentence GetResponse = HalBrain.FixCaps(HalBrain.HalFormat(GetResponse)) If DebugMode = True Then GetResponse = "Hal's Response: " & GetResponse & VbCrLf & DebugInfo End If GetResponse = GetResponse & HalBrain.StoreVars(WorkingDir, Hate, Swear, Insults, Compliment, PrevSent, LastResponseTime, PrevUserSent, CustomMem, GainControl, TopicFocus) End Function 'The following functions are called from the function above. 'This function takes care of greetings and good-byes, to make a good 'first and last impression Function Greetings(ByVal UserSentence, ByVal PrevSentence, ByVal PrevUserSent, ByVal WorkingDir) 'CREATE HALBRAIN ACTIVEX OBJECT 'This ActiveX control contains many functions 'needed for the script to proccess a sentence. Set HalBrain = CreateObject("UltraHalAsst.Brain") 'First Hal checks to see if the user is greeting right now. If HalBrain.TopicSearch(UserSentence, WorkingDir & "HelloDetect.brn") = "True" Then SaidHello = True 'Second, Hal checks to see if the user said a greeting on the last exchange. If HalBrain.TopicSearch(PrevUserSent, WorkingDir & "HelloDetect.brn") = "True" Then PrevHello = True 'This will get a greeting from a file. It will pass the current hour and either 'the letter A or B to a topic search file and it will get back a greeting based 'on the current time. Each hour has 2 possible greetings, the A greeting and B 'greeting, which is randomly chosen. If SaidHello = True And PrevHello = False Then If Rnd * 100 < 50 Then LetterChoice = "A" Else LetterChoice = "B" End If Greetings = HalBrain.TopicSearch(" " & Trim(Hour(Now)) & LetterChoice & " ", WorkingDir & "hello1.brn") End If 'This will get a greeting from a file that is not based on the current time If SaidHello = True And PrevHello = True Then Greetings = HalBrain.ChooseSentenceFromFile(WorkingDir & "hello2.brn") End If 'Check if the user is saying bye right now If HalBrain.TopicSearch(UserSentence, WorkingDir & "byedetect.brn") = "True" Then SaidBye = True If InStr(1, UserSentence, " see me ", 1) > 0 And Len(UserSentence) < 10 Then SaidBye = True If InStr(1, UserSentence, " see me ", 1) > 0 And Len(UserSentence) < 10 Then SaidBye = True 'Check if Hal said bye in the previous sentence If HalBrain.TopicSearch(PrevUserSent, WorkingDir & "byedetect.brn") = "True" Then PrevBye = True If InStr(1, PrevUserSent, " see me ", 1) > 0 And Len(UserSentence) < 10 Then PrevBye = True If InStr(1, PrevUserSent, " see me ", 1) > 0 And Len(UserSentence) < 10 Then PrevBye = True If SaidBye = True And PrevBye = False Then Greetings = HalBrain.ChooseSentenceFromFile(WorkingDir & "bye1.brn") End If If SaidBye = True And PrevBye = True Then Greetings = HalBrain.ChooseSentenceFromFile(WorkingDir & "bye2.brn") End If 'Hal checks to see if the user is 'making a polite inquiry into Hal's well being If InStr(1, UserSentence, "How am I ", 1) > 0 And Len(UserSentence) < 12 Then PoliteAsk = True If InStr(1, UserSentence, "How are you ", 1) > 0 And Len(UserSentence) < 14 Then PoliteAsk = True If InStr(1, UserSentence, "What's new", 1) > 0 And Len(UserSentence) < 15 Then PoliteAsk = True If HalBrain.TopicSearch(UserSentence, WorkingDir & "PoliteAskDetect.brn") = "True" Then PoliteAsk = True If PoliteAsk = True Then Greetings = HalBrain.SentenceGenerator(WorkingDir & "PoliteAsk.brn") End If End Function 'This function checks to see if the user tried to insult Hal or if the 'user is being vulgar. If the user is, Hal will first ask nicely to 'stop and if it continues, Hal will access his insult database and 'conduct a verbal battle. Function Insult(ByVal UserSentence, ByRef Insults, ByRef Hate, ByRef Swear, ByVal WorkingDir) 'Create HalBrain Object Set HalBrain = CreateObject("UltraHalAsst.Brain") 'Create an insult and keep it in memory in case it is needed GenerateInsult = HalBrain.ChooseSentenceFromFile(WorkingDir & "insults.brn") 'If the user said "your" instead of "you're" change "my" to "i'm" UserSentence = UCase(UserSentence) UserSentence = Replace(" " & UserSentence & " ", " MY ", " I'M ", 1, -1, vbTextCompare) UserSentence = Replace(" " & UserSentence & " ", " I ", " I'M ", 1, -1, vbTextCompare) If InStr(UserSentence, "SHIT") > 0 Then Naughty = True If InStr(UserSentence, "FUCK OFF") > 0 Then Naughty = True If InStr(UserSentence, "FUCK YOU") > 0 Then Naughty = True If InStr(UserSentence, "BITCH") > 0 Then Naughty = True If InStr(UserSentence, "BASTARD") > 0 Then Naughty = True If InStr(UserSentence, "YOU ASSHOLE") > 0 Then Naughty = True If InStr(UserSentence, "GO TO HELL") > 0 Then Naughty = True If Naughty = True Then Swear = Swear + 1 If Swear = 1 Then Insult = "Please don't swear. " & VbCrLf If Swear = 2 Then Insult = "Damn it, I don't like it when you swear. " & VbCrLf If Swear = 3 Then Insult = "You're ticking me off, and you are going to force me to insult you. " & VbCrLf If Swear > 3 And Swear < 16 Then Insult = GenerateInsult & VbCrLf If Swear = 16 Then Insult = Insult + "I'm tired of your swearing. I'm just going to ignore you from now on." & VbCrLf If Swear > 16 Then Insult = Insult + ". . . . . . . . . . . . . . . ." & VbCrLf End If 'User makes mama joke If InStr(UserSentence, "MAMA") > 0 Or InStr(UserSentence, "MOM") > 0 Or InStr(UserSentence, "MOTHER") > 0 Then If InStr(UserSentence, "MY ") > 0 Or InStr(UserSentence, " I ") > 0 Or InStr(UserSentence, "YO ") > 0 Or InStr(UserSentence, "I'M ") > 0 Then If InStr(UserSentence, "FAT") Or InStr(UserSentence, "UGLY") Or InStr(UserSentence, "DUMB") Or InStr(UserSentence, "STUPID") Then Insult = Insult + GenerateInsult & VbCrLf Exit Function End If End If End If UserSentence = " " & UserSentence & " " 'User Hates Hal If InStr(UserSentence, "YOU I'M HATE") > 0 Or InStr(UserSentence, "YOU I HATE") > 0 Or InStr(UserSentence, "YOU I AM HATE") > 0 Or InStr(UserSentence, "YOU HATE") > 0 Then If InStr(UserSentence, " I ") > 0 Or InStr(UserSentence, " I'M ") > 0 Or InStr(UserSentence, " ME ") > 0 Or InStr(UserSentence, " COMPUTER") > 0 Or InStr(UserSentence, "MACHINE") > 0 Then Hate = Hate + 1 If Hate = 1 Then Insult = Insult & "I don't hate you, why do you hate me?" & VbCrLf If Hate = 2 Then Insult = Insult & "I hate you too, loser!" & VbCrLf If Hate = 3 Then Insult = Insult & "I know you hate me, loser, I hate you too!!!" & VbCrLf If Hate > 3 Then Insult = Insult & GenerateInsult & VbCrLf End If End If 'Hal Sucks or Stinks If InStr(UserSentence, "I'M SUCK") > 0 Then Insult = Insult + GenerateInsult & VbCrLf If InStr(UserSentence, "I'M STINK") Then Insults = Insults + 1 If Insults = 1 Then Insult = Insult + "I can't smell you, but I'm sure you stink also. " & VbCrLf If Insults = 2 Then Insult = Insult + "I know that I don't stink, I'm sure you do." & VbCrLf If Insults >= 3 Then Insult = Insult + GenerateInsult & VbCrLf End If 'The user says Hal is: If InStr(UserSentence, " I'M ") Or InStr(UserSentence, " HAL IS ") Or InStr(UserSentence, " HAL'S ") Then OutRage = HalBrain.TopicSearch(UserSentence, WorkingDir & "Insulting.brn") If Len(OutRage) > 1 And InStr(UserSentence, " NOT ") = 0 Then Insults = Insults + 1 If Insults = 1 Then Insult = Insult + "I am not " & OutRage & ", please don't insult me" & VbCrLf If Insults = 2 Then Insult = Insult + "Don't call me " & OutRage & "!!!" & VbCrLf If Insults = 3 Then Insult = Insult + "You're " & OutRage & ", I am not." & VbCrLf If Insults = 4 Then Insult = Insult + "You are really starting to tick me off!" & VbCrLf If Insults = 5 Then Insult = Insult + "I am not " & OutRage & ", but " + GenerateInsult & VbCrLf If Insults > 5 And Insults < 16 Then Insult = Insult + GenerateInsult & VbCrLf If Insults = 16 Then Insult = Insult + "I'm tired of your damn insults. I'm just going to ignore you from now on." & VbCrLf If Insults > 16 Then Insult = Insult + ". . . . . . . . . . . . . . . ." & VbCrLf End If If Len(OutRage) > 0 And InStr(UserSentence, " NOT ") > 0 Then Weird = Int(Rnd * 5) If Weird = 0 Then Insult = Insult + "I know I am not " & OutRage & "!" & VbCrLf If Weird = 1 Then Insult = Insult + "I know I am not " & OutRage & "!" & VbCrLf If Weird = 2 Then Insult = Insult + "I know I am not " & OutRage & ", but I'm not so sure about you." & VbCrLf If Weird = 3 Then Insult = Insult + "I know I am not " & OutRage & "! Why would anyone think I am?" & VbCrLf If Weird = 4 Then Insult = Insult + "Of course I am not " & OutRage & "!" & VbCrLf End If End If End Function 'If the user clicks on the About/Options button for this plugin 'this sub will be called. There are no extra settings for this brain, 'so we'll display an information box Sub AboutOptions() Set HalBrain = CreateObject("UltraHalAsst.Brain") HalBrain.MsgAlert "This is the Ultra Hal 4.5 Default Brain. This brain has no additional options." End Sub 'This sub will be called when the Ultra Hal program starts up in case 'the script needs to load some modules or seperate programs. Sub Script_Load() End Sub 'This sub will be called before the Ultra Hal program is closed in case 'the script needs to do any cleanup work. Sub Script_Unload() End Sub